diff --git a/cli/bpbuild/build.go b/cli/bpbuild/build.go index 1eacf702cc3..1e6b7ae22d5 100644 --- a/cli/bpbuild/build.go +++ b/cli/bpbuild/build.go @@ -7,7 +7,7 @@ import ( "time" cloudbuild "google.golang.org/api/cloudbuild/v1" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) const ( @@ -22,12 +22,12 @@ func getCBBuildsWithFilter(projectID string, filter string, cFilters []clientBui ctx := context.Background() cloudbuildService, err := cloudbuild.NewService(ctx) if err != nil { - return nil, fmt.Errorf("error creating cloudbuild service: %v", err) + return nil, fmt.Errorf("error creating cloudbuild service: %w", err) } c, err := cloudbuildService.Projects.Builds.List(projectID).Filter(filter).Do() if err != nil { - return nil, fmt.Errorf("error listing builds with filter %s in project %s: %v", filter, projectID, err) + return nil, fmt.Errorf("error listing builds with filter %s in project %s: %w", filter, projectID, err) } cbBuilds := []*cloudbuild.Build{} @@ -56,7 +56,7 @@ func getCBBuildsWithFilter(projectID string, filter string, cFilters []clientBui for { c, err = cloudbuildService.Projects.Builds.List(projectID).Filter(filter).PageToken(c.NextPageToken).Do() if err != nil { - return nil, fmt.Errorf("error retriving next page with token %s: %v", c.NextPageToken, err) + return nil, fmt.Errorf("error retrieving next page with token %s: %w", c.NextPageToken, err) } appendClientFilteredBuilds(c.Builds) if c.NextPageToken == "" { diff --git a/cli/bpbuild/cmd.go b/cli/bpbuild/cmd.go index 58a23293a29..0d241daa9ed 100644 --- a/cli/bpbuild/cmd.go +++ b/cli/bpbuild/cmd.go @@ -34,7 +34,6 @@ func init() { avgTimeCmd.Flags().StringVar(&avgTimeFlags.lookUpEnd, "end-time", "", "Time to stop computing build step avg in form MM-DD-YYYY. Defaults to current date.") avgTimeCmd.Flags().StringVar(&avgTimeFlags.projectId, "project-id", "cloud-foundation-cicd", "Project ID where builds are executed.") avgTimeCmd.Flags().StringVar(&avgTimeFlags.repoName, "repo", "", "Name of repo that triggered the builds. Defaults to extracting from git config.") - } var Cmd = &cobra.Command{ diff --git a/cli/bpcatalog/cmd.go b/cli/bpcatalog/cmd.go index 539605b6bd3..5fac40bb326 100644 --- a/cli/bpcatalog/cmd.go +++ b/cli/bpcatalog/cmd.go @@ -36,7 +36,6 @@ func init() { listCmd.Flags().Var(&catalogListFlags.format, "format", fmt.Sprintf("Format to display catalog. Defaults to table. Options are %+v.", renderFormats)) listCmd.Flags().Var(&catalogListFlags.sort, "sort", fmt.Sprintf("Sort results. Defaults to created date. Options are %+v.", sortOptions)) - } var Cmd = &cobra.Command{ diff --git a/cli/bpcatalog/gh.go b/cli/bpcatalog/gh.go index ce4cc44f9cf..9b95a5551a2 100644 --- a/cli/bpcatalog/gh.go +++ b/cli/bpcatalog/gh.go @@ -7,7 +7,7 @@ import ( "os" "sort" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v55/github" "golang.org/x/oauth2" ) diff --git a/cli/bpcatalog/render_test.go b/cli/bpcatalog/render_test.go index e12b0105f39..c26d59f9d47 100644 --- a/cli/bpcatalog/render_test.go +++ b/cli/bpcatalog/render_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v55/github" "github.com/stretchr/testify/assert" ) @@ -305,7 +305,6 @@ func TestRenderDocHTML(t *testing.T) { updateExpected(t, expectedPath, got) expected := readFile(t, expectedPath) assert.Equal(t, expected, got) - }) } } diff --git a/cli/bpcatalog/tf.go b/cli/bpcatalog/tf.go index 01d1d5b8af3..5b828648605 100644 --- a/cli/bpcatalog/tf.go +++ b/cli/bpcatalog/tf.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v55/github" ) // sortOption defines the set of sort options for catalog. @@ -55,7 +55,7 @@ var ( func fetchSortedTFRepos(gh *ghService, sortOpt sortOption) (repos, error) { repos, err := gh.fetchRepos() if err != nil { - return nil, fmt.Errorf("error fetching repos: %v", err) + return nil, fmt.Errorf("error fetching repos: %w", err) } repos = repos.filter(func(r *github.Repository) bool { if r.GetArchived() { diff --git a/cli/bpcatalog/tf_test.go b/cli/bpcatalog/tf_test.go index 488d68804df..e5dd5d62f1a 100644 --- a/cli/bpcatalog/tf_test.go +++ b/cli/bpcatalog/tf_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v55/github" "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" ) diff --git a/cli/bpmetadata/markdown_test.go b/cli/bpmetadata/markdown_test.go index 1765f407c98..b76426449f9 100644 --- a/cli/bpmetadata/markdown_test.go +++ b/cli/bpmetadata/markdown_test.go @@ -100,10 +100,10 @@ func TestProcessMarkdownContent(t *testing.T) { getContent: true, want: &mdContent{ listItems: []mdListItem{ - mdListItem{ + { text: "User requests are sent to the front end, which is deployed on two Cloud Run services as containers to support high scalability applications.", }, - mdListItem{ + { text: "The request then lands on the middle tier, which is the API layer that provides access to the backend. This is also deployed on Cloud Run for scalability and ease of deployment in multiple languages. This middleware is a Golang based API.", }, }, @@ -127,19 +127,19 @@ func TestProcessMarkdownContent(t *testing.T) { getContent: true, want: &mdContent{ listItems: []mdListItem{ - mdListItem{ + { text: "document-01", url: "http://google.com/doc-01", }, - mdListItem{ + { text: "document-02", url: "http://google.com/doc-02", }, - mdListItem{ + { text: "document-03", url: "http://google.com/doc-03", }, - mdListItem{ + { text: "document-04", url: "http://google.com/doc-04", }, @@ -155,10 +155,10 @@ func TestProcessMarkdownContent(t *testing.T) { getContent: true, want: &mdContent{ listItems: []mdListItem{ - mdListItem{ + { text: "text-document-01", }, - mdListItem{ + { text: "text-document-02", }, }, diff --git a/cli/bpmetadata/path.go b/cli/bpmetadata/path.go index a5b8b297ecb..4556f0a8611 100644 --- a/cli/bpmetadata/path.go +++ b/cli/bpmetadata/path.go @@ -23,7 +23,7 @@ var ( func fileExists(path string) (bool, error) { info, err := os.Stat(path) if err != nil { - return false, fmt.Errorf("unable to read file at the provided path: %v", err) + return false, fmt.Errorf("unable to read file at the provided path: %w", err) } if info.IsDir() { @@ -48,7 +48,7 @@ func getDirPaths(configPath string, re *regexp.Regexp) ([]*BlueprintMiscContent, paths := []*BlueprintMiscContent{} err := filepath.Walk(configPath, func(path string, info fs.FileInfo, err error) error { if err != nil { - return fmt.Errorf("error accessing examples in the path %q: %v", configPath, err) + return fmt.Errorf("error accessing examples in the path %q: %w", configPath, err) } // skip if this is a .terraform dir @@ -74,7 +74,7 @@ func getDirPaths(configPath string, re *regexp.Regexp) ([]*BlueprintMiscContent, }) if err != nil { - return nil, fmt.Errorf("error accessing examples in the path %q: %v", configPath, err) + return nil, fmt.Errorf("error accessing examples in the path %q: %w", configPath, err) } // Sort by configPath name before returning diff --git a/cli/bpmetadata/path_test.go b/cli/bpmetadata/path_test.go index 993010f5dbf..7651c49dc75 100644 --- a/cli/bpmetadata/path_test.go +++ b/cli/bpmetadata/path_test.go @@ -65,19 +65,19 @@ func TestDirContent(t *testing.T) { path: "content/examples", regex: regexExamples, want: []*BlueprintMiscContent{ - &BlueprintMiscContent{ + { Name: "terraform", Location: "examples/acm/acm-terraform-blog-part1/terraform", }, - &BlueprintMiscContent{ + { Name: "acm-terraform-blog-part2", Location: "examples/acm/acm-terraform-blog-part2", }, - &BlueprintMiscContent{ + { Name: "simple_regional", Location: "examples/simple_regional", }, - &BlueprintMiscContent{ + { Name: "simple_regional_beta", Location: "examples/simple_regional_beta", }, @@ -89,15 +89,15 @@ func TestDirContent(t *testing.T) { path: "content/modules", regex: regexModules, want: []*BlueprintMiscContent{ - &BlueprintMiscContent{ + { Name: "beta-public-cluster", Location: "modules/beta-public-cluster", }, - &BlueprintMiscContent{ + { Name: "binary-authorization", Location: "modules/binary-authorization", }, - &BlueprintMiscContent{ + { Name: "private-cluster", Location: "modules/private-cluster", }, @@ -115,11 +115,11 @@ func TestDirContent(t *testing.T) { path: "content/examples-some-without-tf/examples", regex: regexExamples, want: []*BlueprintMiscContent{ - &BlueprintMiscContent{ + { Name: "terraform", Location: "examples/acm/acm-terraform-blog-part1/terraform", }, - &BlueprintMiscContent{ + { Name: "simple_regional", Location: "examples/simple_regional", }, diff --git a/cli/bpmetadata/repo.go b/cli/bpmetadata/repo.go index 406bc61d751..7c311abb58b 100644 --- a/cli/bpmetadata/repo.go +++ b/cli/bpmetadata/repo.go @@ -34,7 +34,7 @@ func getRepoDetailsByPath(bpPath string, r *repoDetail, readme []byte) { // if it's still in memory. if strings.Contains(bpPath, nestedBpPath) && r.Source != nil { // try to parse the module name from MD which will get - // overriden with "["repoName-submoduleName" if repoName is available + // overridden with "["repoName-submoduleName" if repoName is available r.ModuleName = parseRepoNameFromMd(readme) if r.RepoName != "" { r.ModuleName = r.RepoName + "-" + getBpSubmoduleNameInKebabCase(bpPath) diff --git a/cli/bpmetadata/schema/gcp-blueprint-metadata.json b/cli/bpmetadata/schema/gcp-blueprint-metadata.json index 0748ed5ab15..d74e60607fc 100644 --- a/cli/bpmetadata/schema/gcp-blueprint-metadata.json +++ b/cli/bpmetadata/schema/gcp-blueprint-metadata.json @@ -381,10 +381,8 @@ ] }, "quotaType": { - "patternProperties": { - ".*": { - "type": "string" - } + "additionalProperties": { + "type": "string" }, "type": "object" } @@ -543,10 +541,8 @@ "BlueprintUIInput": { "properties": { "variables": { - "patternProperties": { - ".*": { - "$ref": "#/$defs/DisplayVariable" - } + "additionalProperties": { + "$ref": "#/$defs/DisplayVariable" }, "type": "object" }, @@ -572,10 +568,8 @@ "type": "array" }, "outputs": { - "patternProperties": { - ".*": { - "$ref": "#/$defs/DisplayOutput" - } + "additionalProperties": { + "$ref": "#/$defs/DisplayOutput" }, "type": "object" } @@ -1013,18 +1007,14 @@ "type": "string" }, "labels": { - "patternProperties": { - ".*": { - "type": "string" - } + "additionalProperties": { + "type": "string" }, "type": "object" }, "annotations": { - "patternProperties": { - ".*": { - "type": "string" - } + "additionalProperties": { + "type": "string" }, "type": "object" } diff --git a/cli/bpmetadata/tfconfig.go b/cli/bpmetadata/tfconfig.go index 41c810c88bc..b22bd1a1fe5 100644 --- a/cli/bpmetadata/tfconfig.go +++ b/cli/bpmetadata/tfconfig.go @@ -91,7 +91,7 @@ func getBlueprintVersion(configPath string) (*blueprintVersion, error) { //parse out the blueprint version from the config modName, err := parseBlueprintVersion(versionsFile, diags) if err != nil { - return nil, fmt.Errorf("error parsing blueprint version: %v", err) + return nil, fmt.Errorf("error parsing blueprint version: %w", err) } //parse out the required version from the config diff --git a/cli/bpmetadata/tfconfig_test.go b/cli/bpmetadata/tfconfig_test.go index 6abf9c6e556..7422969273c 100644 --- a/cli/bpmetadata/tfconfig_test.go +++ b/cli/bpmetadata/tfconfig_test.go @@ -174,7 +174,6 @@ func TestTFVersions(t *testing.T) { t.Errorf("getBlueprintVersion() = %v, want %v", got.moduleVersion, tt.wantModuleVersion) return } - } else { if tt.wantModuleVersion != "" && tt.wantRequiredVersion != "" { t.Errorf("getBlueprintVersion() = returned nil when we want core: %v and bpVersion: %v", tt.wantRequiredVersion, tt.wantModuleVersion) diff --git a/cli/bpmetadata/validate.go b/cli/bpmetadata/validate.go index 48f1b42e277..893d9ab8e82 100644 --- a/cli/bpmetadata/validate.go +++ b/cli/bpmetadata/validate.go @@ -54,7 +54,7 @@ func validateMetadataYaml(m string, schema gojsonschema.JSONLoader) error { // prepare metadata for validation by converting it from YAML to JSON mBytes, err := convertYamlToJson(m) if err != nil { - return fmt.Errorf("yaml to json conversion failed for metadata at path %s. error: %s", m, err) + return fmt.Errorf("yaml to json conversion failed for metadata at path %s. error: %w", m, err) } // load metadata from the path @@ -63,7 +63,7 @@ func validateMetadataYaml(m string, schema gojsonschema.JSONLoader) error { // validate metadata against the schema result, err := gojsonschema.Validate(schema, yamlLoader) if err != nil { - return fmt.Errorf("metadata validation failed for %s. error: %s", m, err) + return fmt.Errorf("metadata validation failed for %s. error: %w", m, err) } if !result.Valid() { @@ -84,7 +84,7 @@ func convertYamlToJson(m string) ([]byte, error) { // read metadata for validation b, err := os.ReadFile(m) if err != nil { - return nil, fmt.Errorf("unable to read metadata at path %s. error: %s", m, err) + return nil, fmt.Errorf("unable to read metadata at path %s. error: %w", m, err) } if len(b) == 0 { diff --git a/cli/bptest/cmd.go b/cli/bptest/cmd.go index db78079f7aa..8c3f0f856be 100644 --- a/cli/bptest/cmd.go +++ b/cli/bptest/cmd.go @@ -38,7 +38,7 @@ var Cmd = &cobra.Command{ var listCmd = &cobra.Command{ Use: "list", Short: "list tests", - Long: "Lists both auto discovered and explicit intergration tests", + Long: "Lists both auto discovered and explicit integration tests", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { @@ -80,7 +80,7 @@ var runCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { intTestDir, err := getIntTestDir(flags.testDir) if err != nil { - return fmt.Errorf("error discovering test dir: %v", err) + return fmt.Errorf("error discovering test dir: %w", err) } testStage, err := validateAndGetStage(flags.testStage) if err != nil { diff --git a/cli/bptest/convert.go b/cli/bptest/convert.go index 0426654b512..5854fac827e 100644 --- a/cli/bptest/convert.go +++ b/cli/bptest/convert.go @@ -55,42 +55,42 @@ func convertKitchenTests() error { } err = writeFile(path.Join(intTestPath, goModFilename), fmt.Sprintf(goMod, path.Base(cwd))) if err != nil { - return fmt.Errorf("error writing go mod file: %v", err) + return fmt.Errorf("error writing go mod file: %w", err) } // write discover test discoverTest, err := getTmplFileContents(discoverTestFilename) if err != nil { return err } - err = writeFile(path.Join(intTestPath, discoverTestFilename), string(discoverTest)) + err = writeFile(path.Join(intTestPath, discoverTestFilename), discoverTest) if err != nil { - return fmt.Errorf("error writing discover_test.go: %v", err) + return fmt.Errorf("error writing discover_test.go: %w", err) } testDirs, err := getCurrentTestDirs() if err != nil { - return fmt.Errorf("error getting current test dirs: %v", err) + return fmt.Errorf("error getting current test dirs: %w", err) } for _, dir := range testDirs { err = convertTest(path.Join(intTestPath, dir)) if err != nil { - return fmt.Errorf("error converting %s: %v", dir, err) + return fmt.Errorf("error converting %s: %w", dir, err) } } // remove kitchen err = os.Remove(".kitchen.yml") if err != nil { - return fmt.Errorf("error removing .kitchen.yml: %v", err) + return fmt.Errorf("error removing .kitchen.yml: %w", err) } // convert build file // We use build to identify commands to update and update the commands in the buildFile. // This minimizes unnecessary diffs in build yaml due to round tripping. build, buildFile, err := getBuildFromFile(intTestBuildFilePath) if err != nil { - return fmt.Errorf("error unmarshalling %s: %v", intTestBuildFilePath, err) + return fmt.Errorf("error unmarshalling %s: %w", intTestBuildFilePath, err) } newBuildFile, err := transformBuild(build, buildFile) if err != nil { - return fmt.Errorf("error transforming buildfile: %v", err) + return fmt.Errorf("error transforming buildfile: %w", err) } return writeFile(intTestBuildFilePath, newBuildFile) } @@ -115,12 +115,12 @@ func convertTest(dir string) error { // read inspec.yaml f, err := os.ReadFile(path.Join(dir, inspecInputsFile)) if err != nil { - return fmt.Errorf("error reading inspec file: %s", err) + return fmt.Errorf("error reading inspec file: %w", err) } var inspec inspecInputs err = yaml.Unmarshal(f, &inspec) if err != nil { - return fmt.Errorf("error unmarshalling inspec file: %s", err) + return fmt.Errorf("error unmarshalling inspec file: %w", err) } // get inspec input attributes var inputs []string @@ -131,17 +131,17 @@ func convertTest(dir string) error { testName := path.Base(dir) bpTest, err := getBPTestFromTmpl(testName, inputs) if err != nil { - return fmt.Errorf("error creating blueprint test: %s", err) + return fmt.Errorf("error creating blueprint test: %w", err) } // remove old test err = os.RemoveAll(dir) if err != nil { - return fmt.Errorf("error removing old test dir: %s", err) + return fmt.Errorf("error removing old test dir: %w", err) } // write bpt err = os.MkdirAll(dir, os.ModePerm) if err != nil { - return fmt.Errorf("error creating test dir: %s", err) + return fmt.Errorf("error creating test dir: %w", err) } return writeFile(path.Join(dir, fmt.Sprintf("%s_test.go", strcase.ToSnake(testName))), bpTest) } @@ -151,7 +151,7 @@ func getTmplFileContents(f string) (string, error) { tmplF := path.Join("templates", fmt.Sprintf("%s%s", f, tmplSuffix)) contents, err := templateFiles.ReadFile(tmplF) if err != nil { - return "", fmt.Errorf("error reading %s : %v", tmplF, err) + return "", fmt.Errorf("error reading %s : %w", tmplF, err) } return string(contents), nil } diff --git a/cli/bptest/init.go b/cli/bptest/init.go index c597edf79d0..f522db4a949 100644 --- a/cli/bptest/init.go +++ b/cli/bptest/init.go @@ -39,20 +39,20 @@ func initTest(name string) error { } err = writeFile(goModpath, fmt.Sprintf(goMod, path.Base(cwd))) if err != nil { - return fmt.Errorf("error writing go mod file: %v", err) + return fmt.Errorf("error writing go mod file: %w", err) } } // discover test configs testCfg, err := discovery.GetConfigDirFromTestDir(testDir) if err != nil { - return fmt.Errorf("unable to discover test configs for %s: %v", testDir, err) + return fmt.Errorf("unable to discover test configs for %s: %w", testDir, err) } // Parse config to expose outputs within test mod, diags := tfconfig.LoadModule(testCfg) if diags.HasErrors() { - return fmt.Errorf("error parsing outputs: %v", diags) + return fmt.Errorf("error parsing outputs: %w", diags) } outputs := make([]string, 0, len(mod.Outputs)) for _, op := range mod.Outputs { @@ -63,11 +63,11 @@ func initTest(name string) error { // render and write test testFile, err := getBPTestFromTmpl(name, outputs) if err != nil { - return fmt.Errorf("error creating blueprint test: %v", err) + return fmt.Errorf("error creating blueprint test: %w", err) } err = os.MkdirAll(testDir, os.ModePerm) if err != nil { - return fmt.Errorf("error creating test dir: %v", err) + return fmt.Errorf("error creating test dir: %w", err) } return writeFile(path.Join(testDir, fmt.Sprintf("%s_test.go", strcase.ToSnake(name))), testFile) } diff --git a/cli/bptest/list.go b/cli/bptest/list.go index 112b6cabb72..11c6d90773e 100644 --- a/cli/bptest/list.go +++ b/cli/bptest/list.go @@ -116,7 +116,6 @@ func getExplicitTests(intTestDir string) ([]bpTest, error) { for _, fnName := range testFns { eTests = append(eTests, bpTest{name: fnName, location: testFile, config: testCfg, bptestCfg: bptestCfg}) } - } sort.SliceStable(eTests, func(i, j int) bool { return eTests[i].name < eTests[j].name }) return eTests, nil diff --git a/cli/bptest/list_test.go b/cli/bptest/list_test.go index 59ed336a7cb..f12c8602bf5 100644 --- a/cli/bptest/list_test.go +++ b/cli/bptest/list_test.go @@ -11,7 +11,7 @@ import ( const ( testDirWithDiscovery = "testdata/with-discovery" - intTestDir = "test/intergration" + intTestDir = "test/integration" ) func TestGetDiscoveredTests(t *testing.T) { diff --git a/cli/bptest/run.go b/cli/bptest/run.go index 99ba709edb4..e1597e5d02a 100644 --- a/cli/bptest/run.go +++ b/cli/bptest/run.go @@ -22,7 +22,7 @@ const ( // The tfplan.json files that are being used as input for the terraform validation tests // through the gcloud beta terraform vet are higher than the buffer default value (64*1024), - // after some tests we had evidences that the value were arround from 3MB to 5MB, so + // after some tests we had evidences that the value were around from 3MB to 5MB, so // we choosed a value that is at least 2x higher than the original one to avoid errors. // maxScanTokenSize is the maximum size used to buffer a token // startBufSize is the initial of the buffer token @@ -87,20 +87,19 @@ func streamExec(cmd *exec.Cmd) error { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { - Log.Error(fmt.Sprintf("error reading output: %v", err)) + Log.Error(fmt.Sprintf("error reading output: %s", err)) } }() // run command if err := cmd.Run(); err != nil { - return fmt.Errorf("error running command: %v", err) + return fmt.Errorf("error running command: %w", err) } return nil } // getTestCmd returns a prepared cmd for running the specified tests(s) func getTestCmd(intTestDir string, testStage string, testName string, relTestPkg string) (*exec.Cmd, error) { - // pass all current env vars to test command env := os.Environ() // set test stage env var if specified diff --git a/cli/bptest/run_test.go b/cli/bptest/run_test.go index e74a8e16810..862eb53f956 100644 --- a/cli/bptest/run_test.go +++ b/cli/bptest/run_test.go @@ -62,7 +62,6 @@ func TestIsValidTestName(t *testing.T) { } func TestGetTestCmd(t *testing.T) { - tests := []struct { name string intTestDir string diff --git a/cli/bptest/stages_test.go b/cli/bptest/stages_test.go index ab55b8871c1..33197cd1103 100644 --- a/cli/bptest/stages_test.go +++ b/cli/bptest/stages_test.go @@ -7,7 +7,6 @@ import ( ) func TestValidateAndGetStage(t *testing.T) { - tests := []struct { name string stage string diff --git a/cli/bptest/testdata/with-discovery/test/intergration/.gitkeep b/cli/bptest/testdata/with-discovery/test/integration/.gitkeep similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/.gitkeep rename to cli/bptest/testdata/with-discovery/test/integration/.gitkeep diff --git a/cli/bptest/testdata/with-discovery/test/intergration/bar/.gitkeep b/cli/bptest/testdata/with-discovery/test/integration/bar/.gitkeep similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/bar/.gitkeep rename to cli/bptest/testdata/with-discovery/test/integration/bar/.gitkeep diff --git a/cli/bptest/testdata/with-discovery/test/intergration/bar/bar_test.go b/cli/bptest/testdata/with-discovery/test/integration/bar/bar_test.go similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/bar/bar_test.go rename to cli/bptest/testdata/with-discovery/test/integration/bar/bar_test.go diff --git a/cli/bptest/testdata/with-discovery/test/intergration/discover_test.go b/cli/bptest/testdata/with-discovery/test/integration/discover_test.go similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/discover_test.go rename to cli/bptest/testdata/with-discovery/test/integration/discover_test.go diff --git a/cli/bptest/testdata/with-discovery/test/intergration/foo/.gitkeep b/cli/bptest/testdata/with-discovery/test/integration/foo/.gitkeep similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/foo/.gitkeep rename to cli/bptest/testdata/with-discovery/test/integration/foo/.gitkeep diff --git a/cli/bptest/testdata/with-discovery/test/intergration/foo/foo_test.go b/cli/bptest/testdata/with-discovery/test/integration/foo/foo_test.go similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/foo/foo_test.go rename to cli/bptest/testdata/with-discovery/test/integration/foo/foo_test.go diff --git a/cli/bptest/testdata/with-discovery/test/intergration/quuz/quuz_test.go b/cli/bptest/testdata/with-discovery/test/integration/quuz/quuz_test.go similarity index 100% rename from cli/bptest/testdata/with-discovery/test/intergration/quuz/quuz_test.go rename to cli/bptest/testdata/with-discovery/test/integration/quuz/quuz_test.go diff --git a/cli/cmd/version_test.go b/cli/cmd/version_test.go index 2d584afc63b..b509c448fe7 100644 --- a/cli/cmd/version_test.go +++ b/cli/cmd/version_test.go @@ -22,7 +22,6 @@ func TestVersionCommand(t *testing.T) { } func TestVersionCommandHelp(t *testing.T) { - output, err := ExecuteCommand(rootCmd, "version", "-h") if !strings.HasPrefix(output, versionCmd.Long) { t.Errorf("Unexpected output: %v", output) diff --git a/cli/go.mod b/cli/go.mod index 589df2ce86e..a272bf166a7 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -14,19 +14,19 @@ require ( github.com/golang/protobuf v1.5.3 github.com/gomarkdown/markdown v0.0.0-20230716120725-531d2d74bc12 github.com/google/go-cmp v0.5.9 - github.com/google/go-github/v53 v53.0.0 + github.com/google/go-github/v55 v55.0.0 github.com/hashicorp/hcl/v2 v2.18.0 github.com/hashicorp/terraform-config-inspect v0.0.0-20230825013512-b800820f61b8 github.com/iancoleman/strcase v0.3.0 - github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac - github.com/invopop/jsonschema v0.7.0 + github.com/inconshreveable/log15 v2.16.0+incompatible + github.com/invopop/jsonschema v0.8.0 github.com/itchyny/json2yaml v0.1.4 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/jedib0t/go-pretty/v6 v6.4.7 github.com/manifoldco/promptui v0.9.0 github.com/migueleliasweb/go-github-mock v0.0.19 github.com/mitchellh/go-testing-interface v1.14.2-0.20210821155943-2d9075ca8770 - github.com/open-policy-agent/opa v0.55.0 + github.com/open-policy-agent/opa v0.56.0 github.com/otiai10/copy v1.12.0 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.7.0 @@ -34,11 +34,11 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 - golang.org/x/oauth2 v0.11.0 + golang.org/x/oauth2 v0.12.0 golang.org/x/text v0.13.0 google.golang.org/api v0.138.0 google.golang.org/protobuf v1.31.0 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 sigs.k8s.io/yaml v1.3.0 ) @@ -75,7 +75,6 @@ require ( github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gammazero/deque v0.2.0 // indirect - github.com/ghodss/yaml v1.0.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.4.1 // indirect @@ -98,6 +97,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/cel-go v0.12.6 // indirect github.com/google/gnostic v0.6.9 // indirect + github.com/google/go-github/v53 v53.2.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/s2a-go v0.1.5 // indirect @@ -187,7 +187,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.27.2 // indirect k8s.io/apiextensions-apiserver v0.27.2 // indirect k8s.io/apimachinery v0.27.2 // indirect diff --git a/cli/go.sum b/cli/go.sum index 79cbe9cb907..3ec48a1a246 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -173,7 +173,6 @@ github.com/gammazero/deque v0.2.0 h1:SkieyNB4bg2/uZZLxvya0Pq6diUlwx7m2TeT7GAIWaA github.com/gammazero/deque v0.2.0/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU= github.com/gammazero/workerpool v1.1.3 h1:WixN4xzukFoN0XSeXF6puqEqFTl2mECI9S6W44HWy9Q= github.com/gammazero/workerpool v1.1.3/go.mod h1:wPjyBLDbyKnUn2XwwyD3EEwo9dHutia9/fwNmSHWACc= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -320,8 +319,11 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v53 v53.0.0 h1:T1RyHbSnpHYnoF0ZYKiIPSgPtuJ8G6vgc0MKodXsQDQ= github.com/google/go-github/v53 v53.0.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= +github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI= +github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= +github.com/google/go-github/v55 v55.0.0 h1:4pp/1tNMB9X/LuAhs5i0KQAE40NmiR/y6prLNb9x9cg= +github.com/google/go-github/v55 v55.0.0/go.mod h1:JLahOTA1DnXzhxEymmFF5PP2tSS9JVNj68mSZNDwskA= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -386,13 +388,13 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= -github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac h1:n1DqxAo4oWPMvH1+v+DLYlMCecgumhhgnxAPdqDIFHI= -github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o= +github.com/inconshreveable/log15 v2.16.0+incompatible h1:6nvMKxtGcpgm7q0KiGs+Vc+xDvUXaBqsPKHWKsinccw= +github.com/inconshreveable/log15 v2.16.0+incompatible/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/invopop/jsonschema v0.7.0 h1:2vgQcBz1n256N+FpX3Jq7Y17AjYt46Ig3zIWyy770So= -github.com/invopop/jsonschema v0.7.0/go.mod h1:O9uiLokuu0+MGFlyiaqtWxwqJm41/+8Nj0lD7A36YH0= +github.com/invopop/jsonschema v0.8.0 h1:9Vblm5uNqURXUSaX0QUYcI/Hcu5rrvOz5MbpWgw0VkM= +github.com/invopop/jsonschema v0.8.0/go.mod h1:O9uiLokuu0+MGFlyiaqtWxwqJm41/+8Nj0lD7A36YH0= github.com/itchyny/json2yaml v0.1.4 h1:/pErVOXGG5iTyXHi/QKR4y3uzhLjGTEmmJIy97YT+k8= github.com/itchyny/json2yaml v0.1.4/go.mod h1:6iudhBZdarpjLFRNj+clWLAkGft+9uCcjAZYXUH9eGI= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -479,8 +481,8 @@ github.com/open-policy-agent/frameworks/constraint v0.0.0-20230712214810-96753a2 github.com/open-policy-agent/frameworks/constraint v0.0.0-20230712214810-96753a21c26f/go.mod h1:54/KzLMvA5ndBVpm7B1OjLeV0cUtTLTz2bZ2OtydLpU= github.com/open-policy-agent/gatekeeper/v3 v3.13.0 h1:UUfIo/ZjLa0D6BBQlnSjlZetcAYbp54fZVVCLug4sY0= github.com/open-policy-agent/gatekeeper/v3 v3.13.0/go.mod h1:umWn30oYZ4CGW0kOD7aeIfPwbhCQ9DibK2LTUrRW+bk= -github.com/open-policy-agent/opa v0.55.0 h1:s7Vm4ph6zDqqP/KzvUSw9fsKVsm9lhbTZhYGxxTK7mo= -github.com/open-policy-agent/opa v0.55.0/go.mod h1:2Vh8fj/bXCqSwGMbBiHGrw+O8yrho6T/fdaHt5ROmaQ= +github.com/open-policy-agent/opa v0.56.0 h1:FUSb6MyckjuffOMshEG8P+HGnckxkJ8ENZJHEzAddhk= +github.com/open-policy-agent/opa v0.56.0/go.mod h1:un01L10fkolr00KJMDSqGb2FXCjVyVQOybLtHOfSEfY= github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY= github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww= github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= @@ -744,8 +746,8 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= -golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= -golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= +golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= +golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/cli/launchpad/folder_test.go b/cli/launchpad/folder_test.go index acc848093e2..a203ebc7307 100644 --- a/cli/launchpad/folder_test.go +++ b/cli/launchpad/folder_test.go @@ -1,8 +1,9 @@ package launchpad import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) // newTestFolder generates a fully formed folder for testing usage. diff --git a/cli/launchpad/root.go b/cli/launchpad/root.go index f385dc2c528..23cf6b1d4f6 100644 --- a/cli/launchpad/root.go +++ b/cli/launchpad/root.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/pkg/errors" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // NewGenerate takes file patterns as input YAMLs and output Infrastructure as diff --git a/cli/launchpad/runtime_test.go b/cli/launchpad/runtime_test.go index 465e3178b33..cabfc63ee96 100644 --- a/cli/launchpad/runtime_test.go +++ b/cli/launchpad/runtime_test.go @@ -2,8 +2,9 @@ package launchpad import ( "testing" + + "github.com/stretchr/testify/assert" ) -import "github.com/stretchr/testify/assert" type dummyResource struct { headerYAML diff --git a/cli/report/cmd.go b/cli/report/cmd.go index 9f712e0dc7e..57212cc9e9d 100644 --- a/cli/report/cmd.go +++ b/cli/report/cmd.go @@ -62,7 +62,6 @@ func init() { if err != nil { panic(err) } - } // Cmd represents the base report command diff --git a/cli/scorecard/cmd.go b/cli/scorecard/cmd.go index 2849fe494ff..0e00d1ed1b0 100644 --- a/cli/scorecard/cmd.go +++ b/cli/scorecard/cmd.go @@ -51,7 +51,6 @@ func init() { Cmd.Flags().StringVar(&flags.targetProjectID, "target-project", "", "Project ID to analyze (Works with --bucket and --refresh; conflicts with --target-folder or --target--organization)") Cmd.Flags().StringVar(&flags.targetFolderID, "target-folder", "", "Folder ID to analyze (Works with --bucket and --refresh; conflicts with --target-project or --target--organization)") Cmd.Flags().StringVar(&flags.targetOrgID, "target-organization", "", "Organization ID to analyze (Works with --bucket and --refresh; conflicts with --target-project or --target--folder)") - } // Cmd represents the base scorecard command diff --git a/cli/scorecard/proto.go b/cli/scorecard/proto.go index 55e0246a555..287443f9980 100644 --- a/cli/scorecard/proto.go +++ b/cli/scorecard/proto.go @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,18 +17,17 @@ package scorecard import ( "encoding/json" "strconv" - "strings" - "github.com/golang/protobuf/jsonpb" //nolint //https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/issues/1571 - "github.com/golang/protobuf/proto" //nolint //https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/issues/1571 "github.com/pkg/errors" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" ) func unMarshallAsset(from []byte, to proto.Message) error { // CAI export returns org_policy [1] with update_time if Timestamp format in Seconds and Nanos - // but in jsonpb, Timestamp is expected to be a string in the RFC 3339 format [2]. + // but in protojson, Timestamp is expected to be a string in the RFC 3339 format [2]. // i.e. "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" - // Hence doing a workaround to remove the field so that jsonpb.Unmarshaler can handle org policy. + // Hence doing a workaround to remove the field so that protojson.Unmarshaler can handle org policy. // [1] https://github.com/googleapis/googleapis/blob/master/google/cloud/orgpolicy/v1/orgpolicy.proto // [2] https://godoc.org/google.golang.org/protobuf/types/known/timestamppb#Timestamp @@ -67,8 +66,8 @@ func protoViaJSON(from interface{}, to proto.Message) error { if err != nil { return errors.Wrap(err, "marshaling to json") } - umar := &jsonpb.Unmarshaler{AllowUnknownFields: true} - if err := umar.Unmarshal(strings.NewReader(string(jsn)), to); err != nil { + umar := &protojson.UnmarshalOptions{DiscardUnknown: true} + if err := umar.Unmarshal(jsn, to); err != nil { return errors.Wrap(err, "unmarshaling to proto") } @@ -78,14 +77,13 @@ func protoViaJSON(from interface{}, to proto.Message) error { // interfaceViaJSON uses JSON as an intermediary serialization to convert a protobuf message // into an interface value func interfaceViaJSON(from proto.Message) (interface{}, error) { - marshaler := &jsonpb.Marshaler{} - jsn, err := marshaler.MarshalToString(from) + jsn, err := protojson.Marshal(from) if err != nil { return nil, errors.Wrap(err, "marshaling to json") } var to interface{} - if err := json.Unmarshal([]byte(jsn), &to); err != nil { + if err := json.Unmarshal(jsn, &to); err != nil { return nil, errors.Wrap(err, "unmarshaling to interface") } @@ -95,15 +93,14 @@ func interfaceViaJSON(from proto.Message) (interface{}, error) { // stringViaJSON uses JSON as an intermediary serialization to convert a protobuf message // into an string value func stringViaJSON(from proto.Message) (string, error) { - marshaler := &jsonpb.Marshaler{} - jsn, err := marshaler.MarshalToString(from) + jsn, err := protojson.Marshal(from) if err != nil { return "", errors.Wrap(err, "marshaling to json") } - str, err := strconv.Unquote(jsn) + str, err := strconv.Unquote(string(jsn)) if err != nil { // return original json string if it's not a quoted string - return jsn, nil + return string(jsn), nil } return str, nil } diff --git a/cli/scorecard/score.go b/cli/scorecard/score.go index 42386094aab..9a50b0b350e 100644 --- a/cli/scorecard/score.go +++ b/cli/scorecard/score.go @@ -325,7 +325,6 @@ func (inventory *InventoryConfig) Score(config *ScoringConfig, outputPath string if err != nil { return err } - } else { fmt.Println("No issues found found! You have a perfect score.") } diff --git a/cli/scorecard/violations_test.go b/cli/scorecard/violations_test.go index cbd17b21d97..89f4f06e435 100644 --- a/cli/scorecard/violations_test.go +++ b/cli/scorecard/violations_test.go @@ -78,7 +78,6 @@ func TestGetAssetFromJSON(t *testing.T) { if tc.isIamPolicy && pbAsset.IamPolicy == nil { t.Errorf("wanted IAM Policy bindings, got %s", pbAsset) } - }) } } diff --git a/cli/util/file.go b/cli/util/file.go index 33163876ec7..26b6ae3b6ec 100644 --- a/cli/util/file.go +++ b/cli/util/file.go @@ -28,7 +28,7 @@ func WalkTerraformDirs(topLevelPath string) ([]string, error) { var tfDirs []string err := filepath.Walk(topLevelPath, func(path string, info fs.FileInfo, err error) error { if err != nil { - return fmt.Errorf("failure in accessing the path %q: %v\n", path, err) + return fmt.Errorf("failure in accessing the path %q: %w\n", path, err) } if info.IsDir() && (strings.HasPrefix(info.Name(), tfInternalDirPrefix) || skipDiscoverDirs[info.Name()]) { return filepath.SkipDir @@ -42,7 +42,7 @@ func WalkTerraformDirs(topLevelPath string) ([]string, error) { return nil }) if err != nil { - return nil, fmt.Errorf("error walking the path %q: %v\n", topLevelPath, err) + return nil, fmt.Errorf("error walking the path %q: %w\n", topLevelPath, err) } return tfDirs, nil @@ -51,7 +51,7 @@ func WalkTerraformDirs(topLevelPath string) ([]string, error) { func FindFilesWithPattern(dir string, pattern string, skipPaths []string) ([]string, error) { f, err := os.Stat(dir) if err != nil { - return nil, fmt.Errorf("no such dir: %v", err) + return nil, fmt.Errorf("no such dir: %w", err) } if !f.IsDir() { return nil, fmt.Errorf("expected dir %s: got file", dir) @@ -59,7 +59,7 @@ func FindFilesWithPattern(dir string, pattern string, skipPaths []string) ([]str re, err := regexp.Compile(pattern) if err != nil { - return nil, fmt.Errorf("invalid regex: %v", err) + return nil, fmt.Errorf("invalid regex: %w", err) } filePaths := []string{} @@ -102,5 +102,5 @@ func Exists(path string) (bool, error) { if errors.Is(err, os.ErrNotExist) { return false, nil } - return false, fmt.Errorf("error checking if %s exists: %v", path, err) + return false, fmt.Errorf("error checking if %s exists: %w", path, err) } diff --git a/cli/util/file_test.go b/cli/util/file_test.go index 70c55912b36..f170246e99b 100644 --- a/cli/util/file_test.go +++ b/cli/util/file_test.go @@ -19,7 +19,7 @@ func TestTFDirectories(t *testing.T) { wantErr bool }{ { - name: "multiple directores", + name: "multiple directories", path: "content/examples", want: []string{ "../testdata/bpmetadata/content/examples/acm/acm-terraform-blog-part1/terraform",