diff --git a/internal/acceptance/workflows/acceptance_test.go b/internal/acceptance/workflows/acceptance_test.go index 5021702a9..c87e1d658 100644 --- a/internal/acceptance/workflows/acceptance_test.go +++ b/internal/acceptance/workflows/acceptance_test.go @@ -13,13 +13,14 @@ package workflows import ( "context" - "golang.org/x/exp/slices" "os" "os/exec" "path/filepath" "strings" "testing" + "golang.org/x/exp/slices" + "github.com/cucumber/godog" "github.com/pivotal-cf/kiln/internal/acceptance/workflows/scenario" diff --git a/internal/acceptance/workflows/scenario/initialize.go b/internal/acceptance/workflows/scenario/initialize.go index 674c102e4..1f5007f6c 100644 --- a/internal/acceptance/workflows/scenario/initialize.go +++ b/internal/acceptance/workflows/scenario/initialize.go @@ -10,7 +10,7 @@ import ( // scenarioContext is based on *godog.ScenarioContext type scenarioContext interface { - Step(expr, stepFunc interface{}) + Step(expr, stepFunc any) Before(h godog.BeforeScenarioHook) After(h godog.AfterScenarioHook) } diff --git a/internal/acceptance/workflows/scenario/initialize_test.go b/internal/acceptance/workflows/scenario/initialize_test.go index c25322eac..99d55d237 100644 --- a/internal/acceptance/workflows/scenario/initialize_test.go +++ b/internal/acceptance/workflows/scenario/initialize_test.go @@ -172,7 +172,7 @@ var ( tableType = reflect.TypeOf((*godog.Table)(nil)) ) -func (fake fakeScenarioContext) Step(expr, stepFunc interface{}) { +func (fake fakeScenarioContext) Step(expr, stepFunc any) { fn := reflect.ValueOf(stepFunc) if fn.Kind() != reflect.Func { fake.t.Errorf("expected stepFunc to be %s got %s", reflect.Func, fn.Kind()) diff --git a/internal/acceptance/workflows/scenario/shared_state.go b/internal/acceptance/workflows/scenario/shared_state.go index 52ea6debf..85ecfea47 100644 --- a/internal/acceptance/workflows/scenario/shared_state.go +++ b/internal/acceptance/workflows/scenario/shared_state.go @@ -205,7 +205,7 @@ func runAndLogOnError(ctx context.Context, cmd *exec.Cmd, requireSuccess bool) ( return ctx, nil } -func runAndParseStdoutAsYAML(ctx context.Context, cmd *exec.Cmd, d interface{}) (context.Context, error) { +func runAndParseStdoutAsYAML(ctx context.Context, cmd *exec.Cmd, d any) (context.Context, error) { var stdout, stderr bytes.Buffer fds := ctx.Value(standardFileDescriptorsKey).(standardFileDescriptors) cmd.Stdout = io.MultiWriter(&stdout, fds[1]) diff --git a/internal/acceptance/workflows/scenario/step_funcs_tile.go b/internal/acceptance/workflows/scenario/step_funcs_tile.go index 336b36f4b..2e758d67a 100644 --- a/internal/acceptance/workflows/scenario/step_funcs_tile.go +++ b/internal/acceptance/workflows/scenario/step_funcs_tile.go @@ -11,6 +11,8 @@ import ( "os" "strings" + "github.com/pivotal-cf/kiln/pkg/cargo" + "github.com/cucumber/godog" "gopkg.in/yaml.v2" @@ -78,7 +80,7 @@ func theTileOnlyContainsCompiledReleases(ctx context.Context) error { for _, release := range metadata.Releases { helloReleaseTarball := bytes.NewBuffer(nil) - _, err := tile.ReadReleaseFromFile(tilePath, release.Name, release.Version, helloReleaseTarball) + _, err := cargo.ReadBOSHReleaseFromFile(tilePath, release.Name, release.Version, helloReleaseTarball) if err != nil { return err } diff --git a/internal/baking/fakes/logger.go b/internal/baking/fakes/logger.go index 41e21b063..02f2c0841 100644 --- a/internal/baking/fakes/logger.go +++ b/internal/baking/fakes/logger.go @@ -6,19 +6,19 @@ import ( ) type Logger struct { - PrintlnStub func(...interface{}) + PrintlnStub func(...any) printlnMutex sync.RWMutex printlnArgsForCall []struct { - arg1 []interface{} + arg1 []any } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } -func (fake *Logger) Println(arg1 ...interface{}) { +func (fake *Logger) Println(arg1 ...any) { fake.printlnMutex.Lock() fake.printlnArgsForCall = append(fake.printlnArgsForCall, struct { - arg1 []interface{} + arg1 []any }{arg1}) stub := fake.PrintlnStub fake.recordInvocation("Println", []interface{}{arg1}) @@ -34,13 +34,13 @@ func (fake *Logger) PrintlnCallCount() int { return len(fake.printlnArgsForCall) } -func (fake *Logger) PrintlnCalls(stub func(...interface{})) { +func (fake *Logger) PrintlnCalls(stub func(...any)) { fake.printlnMutex.Lock() defer fake.printlnMutex.Unlock() fake.PrintlnStub = stub } -func (fake *Logger) PrintlnArgsForCall(i int) []interface{} { +func (fake *Logger) PrintlnArgsForCall(i int) []any { fake.printlnMutex.RLock() defer fake.printlnMutex.RUnlock() argsForCall := fake.printlnArgsForCall[i] diff --git a/internal/baking/icon_service_test.go b/internal/baking/icon_service_test.go index 25fbbc4a9..4bf331961 100644 --- a/internal/baking/icon_service_test.go +++ b/internal/baking/icon_service_test.go @@ -43,7 +43,7 @@ var _ = Describe("IconService", func() { Expect(encoding).To(Equal("dGhpcyBpcyBzb21lIGRhdGE=")) Expect(logger.PrintlnCallCount()).To(Equal(1)) - Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Encoding icon..."})) + Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Encoding icon..."})) }) Context("when the icon path is empty", func() { diff --git a/internal/baking/interfaces.go b/internal/baking/interfaces.go index 00ae3e694..dbc8d3591 100644 --- a/internal/baking/interfaces.go +++ b/internal/baking/interfaces.go @@ -8,7 +8,7 @@ import ( //counterfeiter:generate -o ./fakes/logger.go --fake-name Logger . logger type logger interface { - Println(v ...interface{}) + Println(v ...any) } //counterfeiter:generate -o ./fakes/part_reader.go --fake-name PartReader . partReader diff --git a/internal/baking/releases_service.go b/internal/baking/releases_service.go index 0153217d1..090aa5f55 100644 --- a/internal/baking/releases_service.go +++ b/internal/baking/releases_service.go @@ -20,7 +20,7 @@ func NewReleasesService(logger logger, reader partReader) ReleasesService { } } -func (s ReleasesService) FromDirectories(directories []string) (map[string]interface{}, error) { +func (s ReleasesService) FromDirectories(directories []string) (map[string]any, error) { s.logger.Println("Reading release manifests...") var releases []builder.Part @@ -33,7 +33,7 @@ func (s ReleasesService) FromDirectories(directories []string) (map[string]inter releases = append(releases, newReleases...) } - manifests := map[string]interface{}{} + manifests := map[string]any{} for _, rel := range releases { manifests[rel.Name] = rel.Metadata } diff --git a/internal/baking/releases_service_test.go b/internal/baking/releases_service_test.go index 1f7fa16e2..b9145a22c 100644 --- a/internal/baking/releases_service_test.go +++ b/internal/baking/releases_service_test.go @@ -69,13 +69,13 @@ var _ = Describe("ReleasesService", func() { releases, err := service.FromDirectories([]string{tempDir}) Expect(err).NotTo(HaveOccurred()) - Expect(releases).To(Equal(map[string]interface{}{ + Expect(releases).To(Equal(map[string]any{ "some-name": "some-metadata", "other-name": "other-metadata", })) Expect(logger.PrintlnCallCount()).To(Equal(1)) - Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Reading release manifests..."})) + Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Reading release manifests..."})) Expect(reader.ReadCallCount()).To(Equal(2)) Expect(reader.ReadArgsForCall(0)).To(Equal(filepath.Join(tempDir, "other-release.tgz"))) diff --git a/internal/baking/stemcell_service.go b/internal/baking/stemcell_service.go index 0a138efe1..431d7e29f 100644 --- a/internal/baking/stemcell_service.go +++ b/internal/baking/stemcell_service.go @@ -26,7 +26,7 @@ func NewStemcellService(logger logger, tarballReader partReader) StemcellService } } -func (ss StemcellService) FromDirectories(directories []string) (stemcell map[string]interface{}, err error) { +func (ss StemcellService) FromDirectories(directories []string) (stemcell map[string]any, err error) { ss.logger.Println("Reading stemcells from directories...") var tarballs []string @@ -47,7 +47,7 @@ func (ss StemcellService) FromDirectories(directories []string) (stemcell map[st } } - manifests := map[string]interface{}{} + manifests := map[string]any{} for _, tarball := range tarballs { manifest, err := ss.tarballReader.Read(tarball) if err != nil { @@ -66,7 +66,7 @@ func (ss StemcellService) FromDirectories(directories []string) (stemcell map[st return manifests, nil } -func (ss StemcellService) FromTarball(path string) (interface{}, error) { +func (ss StemcellService) FromTarball(path string) (any, error) { if path == "" { return nil, nil } @@ -81,7 +81,7 @@ func (ss StemcellService) FromTarball(path string) (interface{}, error) { return stemcell.Metadata, nil } -func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]interface{}, error) { +func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]any, error) { kilnfileLockPath := fmt.Sprintf("%s.lock", kilnfilePath) kilnfileLockBasename := path.Base(kilnfileLockPath) ss.logger.Println(fmt.Sprintf("Reading stemcell criteria from %s", kilnfileLockBasename)) @@ -111,7 +111,7 @@ func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]interfac stemcell := stemcellCriteria.Metadata - stemcellManifest := map[string]interface{}{ + stemcellManifest := map[string]any{ stemcell.OperatingSystem: stemcellCriteria.Metadata, } diff --git a/internal/baking/stemcell_service_test.go b/internal/baking/stemcell_service_test.go index 6682d003d..b9cdfd7fb 100644 --- a/internal/baking/stemcell_service_test.go +++ b/internal/baking/stemcell_service_test.go @@ -67,7 +67,7 @@ var _ = Describe("StemcellService", func() { stemcell, err := service.FromDirectories([]string{tempDir}) Expect(err).NotTo(HaveOccurred()) - Expect(stemcell).To(Equal(map[string]interface{}{ + Expect(stemcell).To(Equal(map[string]any{ "some-os": builder.StemcellManifest{ Version: "some-version", OperatingSystem: "some-os", @@ -128,7 +128,7 @@ var _ = Describe("StemcellService", func() { })) Expect(logger.PrintlnCallCount()).To(Equal(1)) - Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Reading stemcell manifest..."})) + Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Reading stemcell manifest..."})) Expect(reader.ReadCallCount()).To(Equal(1)) Expect(reader.ReadArgsForCall(0)).To(Equal("some-stemcell-tarball")) diff --git a/internal/baking/template_variables_service.go b/internal/baking/template_variables_service.go index baa2f8d8c..34023480e 100644 --- a/internal/baking/template_variables_service.go +++ b/internal/baking/template_variables_service.go @@ -17,8 +17,8 @@ func NewTemplateVariablesService(fs billy.Basic) TemplateVariablesService { return TemplateVariablesService{filesystem: fs} } -func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []string) (map[string]interface{}, error) { - variables := map[string]interface{}{} +func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []string) (map[string]any, error) { + variables := map[string]any{} for _, path := range paths { err := parseVariablesFromFile(s.filesystem, path, variables) @@ -40,7 +40,7 @@ func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []stri return variables, nil } -func parseVariablesFromFile(fs billy.Basic, path string, variables map[string]interface{}) error { +func parseVariablesFromFile(fs billy.Basic, path string, variables map[string]any) error { file, err := fs.Open(path) if err != nil { return fmt.Errorf("unable to open file %q: %w", path, err) diff --git a/internal/baking/template_variables_service_test.go b/internal/baking/template_variables_service_test.go index fdd582aa9..cf4718ad1 100644 --- a/internal/baking/template_variables_service_test.go +++ b/internal/baking/template_variables_service_test.go @@ -49,9 +49,9 @@ key-3: value-3 It("parses template variables from a collection of files", func() { variables, err := service.FromPathsAndPairs([]string{path}, nil) Expect(err).NotTo(HaveOccurred()) - Expect(variables).To(Equal(map[string]interface{}{ - "key-1": map[interface{}]interface{}{ - "key-2": []interface{}{ + Expect(variables).To(Equal(map[string]any{ + "key-1": map[any]any{ + "key-2": []any{ "value-1", "value-2", }, @@ -66,7 +66,7 @@ key-3: value-3 "key-2=value-2", }) Expect(err).NotTo(HaveOccurred()) - Expect(variables).To(Equal(map[string]interface{}{ + Expect(variables).To(Equal(map[string]any{ "key-1": "value-1", "key-2": "value-2", })) diff --git a/internal/builder/fakes/logger.go b/internal/builder/fakes/logger.go index 831cc7272..ec7d83348 100644 --- a/internal/builder/fakes/logger.go +++ b/internal/builder/fakes/logger.go @@ -16,10 +16,10 @@ type Logger struct { } } -func (l *Logger) Printf(format string, v ...interface{}) { +func (l *Logger) Printf(format string, v ...any) { l.PrintfCall.Receives.LogLines = append(l.PrintfCall.Receives.LogLines, fmt.Sprintf(format, v...)) } -func (l *Logger) Println(v ...interface{}) { +func (l *Logger) Println(v ...any) { l.PrintlnCall.Receives.LogLines = append(l.PrintlnCall.Receives.LogLines, fmt.Sprintf("%s", v...)) } diff --git a/internal/builder/interfaces.go b/internal/builder/interfaces.go index 5031b4aa3..a556befd1 100644 --- a/internal/builder/interfaces.go +++ b/internal/builder/interfaces.go @@ -3,10 +3,10 @@ package builder import "io" type logger interface { - Printf(format string, v ...interface{}) - Println(v ...interface{}) + Printf(format string, v ...any) + Println(v ...any) } -type Metadata map[string]interface{} +type Metadata map[string]any func closeAndIgnoreError(c io.Closer) { _ = c.Close() } diff --git a/internal/builder/interpolator.go b/internal/builder/interpolator.go index 1ee226c90..bff5ebe65 100644 --- a/internal/builder/interpolator.go +++ b/internal/builder/interpolator.go @@ -35,17 +35,17 @@ type Interpolator struct{} type InterpolateInput struct { Version string - BOSHVariables map[string]interface{} - Variables map[string]interface{} - ReleaseManifests map[string]interface{} - StemcellManifests map[string]interface{} - StemcellManifest interface{} - FormTypes map[string]interface{} + BOSHVariables map[string]any + Variables map[string]any + ReleaseManifests map[string]any + StemcellManifests map[string]any + StemcellManifest any + FormTypes map[string]any IconImage string - InstanceGroups map[string]interface{} - Jobs map[string]interface{} - PropertyBlueprints map[string]interface{} - RuntimeConfigs map[string]interface{} + InstanceGroups map[string]any + Jobs map[string]any + PropertyBlueprints map[string]any + RuntimeConfigs map[string]any StubReleases bool MetadataGitSHA func() (string, error) } @@ -124,7 +124,7 @@ func (i Interpolator) functions(input InterpolateInput) template.FuncMap { if !ok { if input.StubReleases { - val = map[string]interface{}{ + val = map[string]any{ "name": name, "version": "UNKNOWN", "file": fmt.Sprintf("%s-UNKNOWN.tgz", name), @@ -221,7 +221,7 @@ func (i Interpolator) functions(input InterpolateInput) template.FuncMap { return i.interpolateValueIntoYAML(input, name, val) }, "select": func(field, input string) (string, error) { - object := map[string]interface{}{} + object := map[string]any{} err := json.Unmarshal([]byte(input), &object) if err != nil { @@ -263,7 +263,7 @@ func (i Interpolator) interpolate(input InterpolateInput, name string, templateY return buffer.Bytes(), nil } -func (i Interpolator) interpolateValueIntoYAML(input InterpolateInput, name string, val interface{}) (string, error) { +func (i Interpolator) interpolateValueIntoYAML(input InterpolateInput, name string, val any) (string, error) { initialYAML, err := yaml.Marshal(val) if err != nil { return "", err // should never happen @@ -288,7 +288,7 @@ func (i Interpolator) yamlMarshalOneLine(yamlContents []byte) ([]byte, error) { } func (i Interpolator) prettyPrint(inputYAML []byte) ([]byte, error) { - var data interface{} + var data any err := yaml.Unmarshal(inputYAML, &data) if err != nil { return []byte{}, err // should never happen @@ -297,7 +297,7 @@ func (i Interpolator) prettyPrint(inputYAML []byte) ([]byte, error) { return yaml.Marshal(data) } -func PreProcessMetadataWithTileFunction(variables map[string]interface{}, name string, dst io.Writer, in []byte) error { +func PreProcessMetadataWithTileFunction(variables map[string]any, name string, dst io.Writer, in []byte) error { tileFN := tileFunc(variables) t, err := template.New(name). @@ -313,9 +313,9 @@ func PreProcessMetadataWithTileFunction(variables map[string]interface{}, name s // tileFunc is used both in pre-processing and is also available // to Interpolator -func tileFunc(variables map[string]interface{}) func() (string, error) { +func tileFunc(variables map[string]any) func() (string, error) { if variables == nil { - variables = make(map[string]interface{}) + variables = make(map[string]any) } return func() (string, error) { diff --git a/internal/builder/interpolator_test.go b/internal/builder/interpolator_test.go index 31ff58e06..bca7b7b25 100644 --- a/internal/builder/interpolator_test.go +++ b/internal/builder/interpolator_test.go @@ -49,16 +49,16 @@ selected_value: $( release "some-release" | select "version" ) input = builder.InterpolateInput{ Version: "3.4.5", - BOSHVariables: map[string]interface{}{ + BOSHVariables: map[string]any{ "some-bosh-variable": builder.Metadata{ "name": "some-bosh-variable", "type": "some-bosh-type", }, }, - Variables: map[string]interface{}{ + Variables: map[string]any{ "some-variable": "some-value", }, - ReleaseManifests: map[string]interface{}{ + ReleaseManifests: map[string]any{ "some-release": builder.ReleaseManifest{ Name: "some-release", Version: "1.2.3", @@ -70,14 +70,14 @@ selected_value: $( release "some-release" | select "version" ) Version: "2.3.4", OperatingSystem: "an-operating-system", }, - FormTypes: map[string]interface{}{ + FormTypes: map[string]any{ "some-form": builder.Metadata{ "name": "some-form", "label": "some-form-label", }, }, IconImage: "some-icon-image", - InstanceGroups: map[string]interface{}{ + InstanceGroups: map[string]any{ "some-instance-group": builder.Metadata{ "name": "some-instance-group", "templates": []string{ @@ -85,13 +85,13 @@ selected_value: $( release "some-release" | select "version" ) }, }, }, - Jobs: map[string]interface{}{ + Jobs: map[string]any{ "some-job": builder.Metadata{ "name": "some-job", "release": "some-release", }, }, - PropertyBlueprints: map[string]interface{}{ + PropertyBlueprints: map[string]any{ "some-templated-property": builder.Metadata{ "name": "some-templated-property", "type": "boolean", @@ -105,7 +105,7 @@ selected_value: $( release "some-release" | select "version" ) "default": "some-value", }, }, - RuntimeConfigs: map[string]interface{}{ + RuntimeConfigs: map[string]any{ "some-runtime-config": builder.Metadata{ "name": "some-runtime-config", "runtime_config": "some-addon-runtime-config\n", @@ -198,10 +198,10 @@ some_form_types: - $( form "some-form" )` input = builder.InterpolateInput{ - Variables: map[string]interface{}{ + Variables: map[string]any{ "some-form-variable": "variable-form-label", }, - FormTypes: map[string]interface{}{ + FormTypes: map[string]any{ "some-form": builder.Metadata{ "name": "some-form", "label": `$( variable "some-form-variable" )`, @@ -223,7 +223,7 @@ some_form_types: BeforeEach(func() { input = builder.InterpolateInput{ - ReleaseManifests: map[string]interface{}{ + ReleaseManifests: map[string]any{ "some-release": builder.ReleaseManifest{ Name: "some-release", Version: "1.2.3", @@ -231,7 +231,7 @@ some_form_types: SHA1: "123abc", }, }, - StemcellManifests: map[string]interface{}{ + StemcellManifests: map[string]any{ "windows": builder.StemcellManifest{ OperatingSystem: "windows", Version: "2019.4", @@ -288,7 +288,7 @@ additional_stemcells_criteria: stemcell_criteria: $( stemcell )` input = builder.InterpolateInput{ - ReleaseManifests: map[string]interface{}{ + ReleaseManifests: map[string]any{ "some-release": builder.ReleaseManifest{ Name: "some-release", Version: "1.2.3", @@ -296,7 +296,7 @@ stemcell_criteria: $( stemcell )` SHA1: "123abc", }, }, - StemcellManifests: map[string]interface{}{ + StemcellManifests: map[string]any{ "centOS": builder.StemcellManifest{ OperatingSystem: "centOS", Version: "5.4", @@ -328,7 +328,7 @@ some_runtime_configs: - $( runtime_config "some-runtime-config" )` input = builder.InterpolateInput{ - ReleaseManifests: map[string]interface{}{ + ReleaseManifests: map[string]any{ "some-release": builder.ReleaseManifest{ Name: "some-release", Version: "1.2.3", @@ -336,7 +336,7 @@ some_runtime_configs: SHA1: "123abc", }, }, - RuntimeConfigs: map[string]interface{}{ + RuntimeConfigs: map[string]any{ "some-runtime-config": builder.Metadata{ "name": "some-runtime-config", "runtime_config": `releases: @@ -350,14 +350,14 @@ some_runtime_configs: interpolatedYAML, err := interpolator.Interpolate(input, "", []byte(templateYAML)) Expect(err).NotTo(HaveOccurred()) - var output map[string]interface{} + var output map[string]any err = yaml.Unmarshal(interpolatedYAML, &output) Expect(err).NotTo(HaveOccurred()) Expect(output).To(HaveKey("some_runtime_configs")) - configs, ok := output["some_runtime_configs"].([]interface{}) + configs, ok := output["some_runtime_configs"].([]any) Expect(ok).To(BeTrue()) - config, ok := configs[0].(map[interface{}]interface{}) + config, ok := configs[0].(map[any]any) Expect(ok).To(BeTrue()) Expect(config).To(HaveKeyWithValue("name", "some-runtime-config")) @@ -371,7 +371,7 @@ releases: Context("when the interpolated runtime config does not have a runtime_config key", func() { JustBeforeEach(func() { - input.RuntimeConfigs = map[string]interface{}{ + input.RuntimeConfigs = map[string]any{ "some-runtime-config": builder.Metadata{ "name": "some-runtime-config", }, @@ -406,7 +406,7 @@ some_runtime_configs: Context("failure cases", func() { Context("when the requested form name is not found", func() { It("returns an error", func() { - input.FormTypes = map[string]interface{}{} + input.FormTypes = map[string]any{} interpolator := builder.NewInterpolator() _, err := interpolator.Interpolate(input, "", []byte(templateYAML)) @@ -417,7 +417,7 @@ some_runtime_configs: Context("when the requested property blueprint is not found", func() { It("returns an error", func() { - input.PropertyBlueprints = map[string]interface{}{} + input.PropertyBlueprints = map[string]any{} interpolator := builder.NewInterpolator() _, err := interpolator.Interpolate(input, "", []byte(templateYAML)) @@ -428,7 +428,7 @@ some_runtime_configs: Context("when the requested runtime config is not found", func() { It("returns an error", func() { - input.RuntimeConfigs = map[string]interface{}{} + input.RuntimeConfigs = map[string]any{} interpolator := builder.NewInterpolator() _, err := interpolator.Interpolate(input, "", []byte(templateYAML)) @@ -439,7 +439,7 @@ some_runtime_configs: Context("when the nested form contains invalid templating", func() { It("returns an error", func() { - input.FormTypes = map[string]interface{}{ + input.FormTypes = map[string]any{ "some-form": builder.Metadata{ "name": "some-form", "label": "$( invalid_helper )", @@ -711,13 +711,13 @@ tile: {{if eq tile "ert" -}} {{- end -}} ` var buf bytes.Buffer - err := builder.PreProcessMetadataWithTileFunction(map[string]interface{}{"tile_name": "ERT"}, "m.yml", &buf, []byte(partYML)) + err := builder.PreProcessMetadataWithTileFunction(map[string]any{"tile_name": "ERT"}, "m.yml", &buf, []byte(partYML)) please.Expect(err).NotTo(HaveOccurred()) please.Expect(buf.Bytes()).To(MatchYAML(`tile: big-foot`)) buf.Reset() - err = builder.PreProcessMetadataWithTileFunction(map[string]interface{}{"tile_name": "SRT"}, "m.yml", &buf, []byte(partYML)) + err = builder.PreProcessMetadataWithTileFunction(map[string]any{"tile_name": "SRT"}, "m.yml", &buf, []byte(partYML)) please.Expect(err).NotTo(HaveOccurred()) please.Expect(buf.Bytes()).To(MatchYAML(`tile: small-foot`)) }) @@ -726,7 +726,7 @@ tile: {{if eq tile "ert" -}} please := NewWithT(t) partYML := `tile: {{tile}}` - err := builder.PreProcessMetadataWithTileFunction(map[string]interface{}{"tile_name": 27}, "m.yml", io.Discard, []byte(partYML)) + err := builder.PreProcessMetadataWithTileFunction(map[string]any{"tile_name": 27}, "m.yml", io.Discard, []byte(partYML)) please.Expect(err).To(And( HaveOccurred(), MatchError(ContainSubstring("expected string")), @@ -737,7 +737,7 @@ tile: {{if eq tile "ert" -}} please := NewWithT(t) partYML := `tile: {{tile}}` - err := builder.PreProcessMetadataWithTileFunction(make(map[string]interface{}), "m.yml", io.Discard, []byte(partYML)) + err := builder.PreProcessMetadataWithTileFunction(make(map[string]any), "m.yml", io.Discard, []byte(partYML)) please.Expect(err).To(And( HaveOccurred(), MatchError(ContainSubstring("could not find variable")), diff --git a/internal/builder/metadata_parts_directory_reader.go b/internal/builder/metadata_parts_directory_reader.go index 3efb96064..7a6e36c3b 100644 --- a/internal/builder/metadata_parts_directory_reader.go +++ b/internal/builder/metadata_parts_directory_reader.go @@ -20,7 +20,7 @@ type MetadataPartsDirectoryReader struct { type Part struct { File string Name string - Metadata interface{} + Metadata any } func NewMetadataPartsDirectoryReader() MetadataPartsDirectoryReader { @@ -48,7 +48,7 @@ func (r MetadataPartsDirectoryReader) Read(path string) ([]Part, error) { return r.orderAlphabeticallyByName(path, parts) } -func (r MetadataPartsDirectoryReader) ParseMetadataTemplates(directories []string, variables map[string]interface{}) (map[string]interface{}, error) { +func (r MetadataPartsDirectoryReader) ParseMetadataTemplates(directories []string, variables map[string]any) (map[string]any, error) { var releases []Part for _, directory := range directories { newReleases, err := r.ReadPreProcess(directory, variables) @@ -59,7 +59,7 @@ func (r MetadataPartsDirectoryReader) ParseMetadataTemplates(directories []strin releases = append(releases, newReleases...) } - manifests := map[string]interface{}{} + manifests := map[string]any{} for _, rel := range releases { manifests[rel.Name] = rel.Metadata } @@ -67,7 +67,7 @@ func (r MetadataPartsDirectoryReader) ParseMetadataTemplates(directories []strin return manifests, nil } -func (r MetadataPartsDirectoryReader) ReadPreProcess(path string, variables map[string]interface{}) ([]Part, error) { +func (r MetadataPartsDirectoryReader) ReadPreProcess(path string, variables map[string]any) ([]Part, error) { parts, err := r.readMetadataRecursivelyFromDir(path, variables) if err != nil { return []Part{}, err @@ -80,7 +80,7 @@ func (r MetadataPartsDirectoryReader) ReadPreProcess(path string, variables map[ return r.orderAlphabeticallyByName(path, parts) } -func (r MetadataPartsDirectoryReader) readMetadataRecursivelyFromDir(p string, variables map[string]interface{}) ([]Part, error) { +func (r MetadataPartsDirectoryReader) readMetadataRecursivelyFromDir(p string, variables map[string]any) ([]Part, error) { var parts []Part var buf bytes.Buffer @@ -108,9 +108,9 @@ func (r MetadataPartsDirectoryReader) readMetadataRecursivelyFromDir(p string, v data = buf.Bytes() } - var vars interface{} + var vars any if r.topLevelKey != "" { - var fileVars map[string]interface{} + var fileVars map[string]any err = yaml.Unmarshal(data, &fileVars) if err != nil { return fmt.Errorf("cannot unmarshal '%s': %s", filePath, err) @@ -139,11 +139,11 @@ func (r MetadataPartsDirectoryReader) readMetadataRecursivelyFromDir(p string, v return parts, err } -func (r MetadataPartsDirectoryReader) readMetadataIntoParts(fileName string, vars interface{}, parts []Part) ([]Part, error) { +func (r MetadataPartsDirectoryReader) readMetadataIntoParts(fileName string, vars any, parts []Part) ([]Part, error) { switch v := vars.(type) { - case []interface{}: + case []any: for _, item := range v { - i, ok := item.(map[interface{}]interface{}) + i, ok := item.(map[any]any) if !ok { return []Part{}, fmt.Errorf("metadata item '%v' must be a map", item) } @@ -155,7 +155,7 @@ func (r MetadataPartsDirectoryReader) readMetadataIntoParts(fileName string, var parts = append(parts, part) } - case map[interface{}]interface{}: + case map[any]any: part, err := r.buildPartFromMetadata(v, fileName) if err != nil { return []Part{}, err @@ -168,7 +168,7 @@ func (r MetadataPartsDirectoryReader) readMetadataIntoParts(fileName string, var return parts, nil } -func (r MetadataPartsDirectoryReader) buildPartFromMetadata(metadata map[interface{}]interface{}, legacyFilename string) (Part, error) { +func (r MetadataPartsDirectoryReader) buildPartFromMetadata(metadata map[any]any, legacyFilename string) (Part, error) { name, ok := metadata["alias"].(string) if !ok { name, ok = metadata["name"].(string) @@ -194,7 +194,7 @@ func (r MetadataPartsDirectoryReader) orderWithOrderFromFile(path string, parts return []Part{}, err } - var files map[string][]interface{} + var files map[string][]any err = yaml.Unmarshal(data, &files) if err != nil { return []Part{}, fmt.Errorf("invalid format for %q: %w", orderPath, err) diff --git a/internal/builder/metadata_parts_directory_reader_test.go b/internal/builder/metadata_parts_directory_reader_test.go index db3f83dd2..e98286924 100644 --- a/internal/builder/metadata_parts_directory_reader_test.go +++ b/internal/builder/metadata_parts_directory_reader_test.go @@ -55,7 +55,7 @@ type: password { File: "vars-file-1.yml", Name: "variable-1", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-1", "type": "certificate", }, @@ -63,7 +63,7 @@ type: password { File: "vars-file-1.yml", Name: "variable-2-alias", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-2", "type": "user", }, @@ -71,7 +71,7 @@ type: password { File: "vars-file-2.yml", Name: "variable-3", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-3", "type": "password", }, @@ -171,7 +171,7 @@ variables: { File: "vars-file-1.yml", Name: "variable-1", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-1", "type": "certificate", }, @@ -179,7 +179,7 @@ variables: { File: "vars-file-1.yml", Name: "variable-2", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-2", "type": "user", }, @@ -187,7 +187,7 @@ variables: { File: "vars-file-2.yml", Name: "variable-3", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-3", "type": "password", }, @@ -273,7 +273,7 @@ variables: { File: "vars-file-2.yml", Name: "variable-3", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-3", "type": "password", }, @@ -281,7 +281,7 @@ variables: { File: "vars-file-1.yml", Name: "variable-2", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-2", "type": "user", }, @@ -289,7 +289,7 @@ variables: { File: "vars-file-1.yml", Name: "variable-1", - Metadata: map[interface{}]interface{}{ + Metadata: map[any]any{ "name": "variable-1", "type": "certificate", }, diff --git a/internal/builder/release_manifest_reader.go b/internal/builder/release_manifest_reader.go index bb62e5b80..3c212d74b 100644 --- a/internal/builder/release_manifest_reader.go +++ b/internal/builder/release_manifest_reader.go @@ -1,18 +1,16 @@ package builder import ( - "archive/tar" - "compress/gzip" "crypto/sha1" + "encoding/hex" "fmt" "io" "path/filepath" - "strings" + + "github.com/pivotal-cf/kiln/pkg/cargo" "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/osfs" - - "gopkg.in/yaml.v2" ) type ReleaseManifest struct { @@ -24,17 +22,6 @@ type ReleaseManifest struct { StemcellVersion string `yaml:"-"` } -// inputReleaseManifest is a subset of release.MF -type inputReleaseManifest struct { - Name string `yaml:"name"` - Version string `yaml:"version"` - CompiledPackages []compiledPackage `yaml:"compiled_packages"` -} - -type compiledPackage struct { - Stemcell string `yaml:"stemcell"` -} - type ReleaseManifestReader struct { fs billy.Filesystem } @@ -54,54 +41,14 @@ func (r ReleaseManifestReader) Read(releaseTarball string) (Part, error) { } defer closeAndIgnoreError(file) - // TODO: use component.ReadReleaseManifest - // we could not do it yet due to a circular package reference where we import builder in the local release source - - gr, err := gzip.NewReader(file) - if err != nil { - return Part{}, err - } - defer closeAndIgnoreError(gr) - - tr := tar.NewReader(gr) - - var header *tar.Header - for { - header, err = tr.Next() - if err != nil { - if err == io.EOF { - return Part{}, fmt.Errorf("could not find release.MF in %q", releaseTarball) - } - - return Part{}, fmt.Errorf("error while reading %q: %s", releaseTarball, err) - } - - if filepath.Base(header.Name) == "release.MF" { - break - } - } - - var inputReleaseManifest inputReleaseManifest - inputReleaseManifestContents, err := io.ReadAll(tr) - if err != nil { - return Part{}, err // NOTE: cannot replicate this error scenario in a test - } - - err = yaml.Unmarshal(inputReleaseManifestContents, &inputReleaseManifest) + inputReleaseManifest, err := cargo.ReadProductTemplatePartFromBOSHReleaseTarball(file) if err != nil { return Part{}, err } - var stemcellOS, stemcellVersion string - compiledPackages := inputReleaseManifest.CompiledPackages - if len(compiledPackages) > 0 { - inputStemcell := inputReleaseManifest.CompiledPackages[0].Stemcell - stemcellParts := strings.Split(inputStemcell, "/") - if len(stemcellParts) != 2 { - return Part{}, fmt.Errorf("Invalid format for compiled package stemcell inside release.MF (expected 'os/version'): %s", inputStemcell) - } - stemcellOS = stemcellParts[0] - stemcellVersion = stemcellParts[1] + stemcellOS, stemcellVersion, stemcellOK := inputReleaseManifest.Stemcell() + if !stemcellOK && len(inputReleaseManifest.CompiledPackages) > 0 { + return Part{}, fmt.Errorf("%s/%s has invalid stemcell: %q", inputReleaseManifest.Name, inputReleaseManifest.Version, inputReleaseManifest.CompiledPackages[0].Stemcell) } outputReleaseManifest := ReleaseManifest{ @@ -123,7 +70,7 @@ func (r ReleaseManifestReader) Read(releaseTarball string) (Part, error) { return Part{}, err // NOTE: cannot replicate this error scenario in a test } - outputReleaseManifest.SHA1 = fmt.Sprintf("%x", hash.Sum(nil)) + outputReleaseManifest.SHA1 = hex.EncodeToString(hash.Sum(nil)) return Part{ File: releaseTarball, diff --git a/internal/builder/release_manifest_reader_test.go b/internal/builder/release_manifest_reader_test.go index e6fd9b5fb..48c8193d9 100644 --- a/internal/builder/release_manifest_reader_test.go +++ b/internal/builder/release_manifest_reader_test.go @@ -6,7 +6,7 @@ import ( "bytes" "compress/gzip" "crypto/sha1" - "fmt" + "encoding/hex" "io" "os" "path/filepath" @@ -59,7 +59,7 @@ func createReleaseTarball(releaseMetadata string) (*os.File, string) { _, err = io.Copy(hash, file) Expect(err).NotTo(HaveOccurred()) - releaseSHA1 := fmt.Sprintf("%x", hash.Sum(nil)) + releaseSHA1 := hex.EncodeToString(hash.Sum(nil)) err = file.Close() Expect(err).NotTo(HaveOccurred()) @@ -183,7 +183,7 @@ version: 1.2.3 Expect(gw.Close()).NotTo(HaveOccurred()) _, err = reader.Read(tarball.Name()) - Expect(err).To(MatchError(fmt.Sprintf("could not find release.MF in %q", tarball.Name()))) + Expect(err).To(MatchError("failed to find release.MF in tarball")) }) }) @@ -220,7 +220,7 @@ version: 1.2.3 Expect(err).NotTo(HaveOccurred()) _, err = reader.Read(tarball.Name()) - Expect(err).To(MatchError(fmt.Sprintf("could not find release.MF in %q", tarball.Name()))) + Expect(err).To(MatchError("failed to find release.MF in tarball")) }) }) @@ -242,7 +242,7 @@ version: 1.2.3 Expect(err).NotTo(HaveOccurred()) _, err = reader.Read(tarball.Name()) - Expect(err).To(MatchError(fmt.Sprintf("error while reading %q: unexpected EOF", tarball.Name()))) + Expect(err).To(MatchError("unexpected EOF")) }) }) diff --git a/internal/builder/stemcell_manifest_reader.go b/internal/builder/stemcell_manifest_reader.go index ae3330d8b..6f6a6af92 100644 --- a/internal/builder/stemcell_manifest_reader.go +++ b/internal/builder/stemcell_manifest_reader.go @@ -17,7 +17,7 @@ type StemcellManifest struct { // the input field in stemcell.MF is called `operating_system` while the output field is `os` -func (s StemcellManifest) MarshalYAML() (interface{}, error) { +func (s StemcellManifest) MarshalYAML() (any, error) { return struct { Version string `yaml:"version"` OperatingSystem string `yaml:"os"` diff --git a/internal/commands/bake.go b/internal/commands/bake.go index 07c389317..fd69ac2a0 100644 --- a/internal/commands/bake.go +++ b/internal/commands/bake.go @@ -30,24 +30,24 @@ type tileWriter interface { //counterfeiter:generate -o ./fakes/from_directories.go --fake-name FromDirectories . fromDirectories type fromDirectories interface { - FromDirectories(directories []string) (map[string]interface{}, error) + FromDirectories(directories []string) (map[string]any, error) } //counterfeiter:generate -o ./fakes/parse_metadata_templates.go --fake-name MetadataTemplatesParser . metadataTemplatesParser type metadataTemplatesParser interface { - ParseMetadataTemplates(directories []string, variables map[string]interface{}) (map[string]interface{}, error) + ParseMetadataTemplates(directories []string, variables map[string]any) (map[string]any, error) } //counterfeiter:generate -o ./fakes/stemcell_service.go --fake-name StemcellService . stemcellService type stemcellService interface { fromDirectories - FromKilnfile(path string) (stemcell map[string]interface{}, err error) - FromTarball(path string) (stemcell interface{}, err error) + FromKilnfile(path string) (stemcell map[string]any, err error) + FromTarball(path string) (stemcell any, err error) } //counterfeiter:generate -o ./fakes/template_variables_service.go --fake-name TemplateVariablesService . templateVariablesService type templateVariablesService interface { - FromPathsAndPairs(paths []string, pairs []string) (templateVariables map[string]interface{}, err error) + FromPathsAndPairs(paths []string, pairs []string) (templateVariables map[string]any, err error) } //counterfeiter:generate -o ./fakes/icon_service.go --fake-name IconService . iconService @@ -408,8 +408,8 @@ func (b Bake) Execute(args []string) error { return fmt.Errorf("failed to parse releases: %s", err) } - var stemcellManifests map[string]interface{} - var stemcellManifest interface{} + var stemcellManifests map[string]any + var stemcellManifest any if b.Options.StemcellTarball != "" { // TODO remove when stemcell tarball is deprecated stemcellManifest, err = b.stemcell.FromTarball(b.Options.StemcellTarball) diff --git a/internal/commands/bake_test.go b/internal/commands/bake_test.go index 711b7c485..48928cdf3 100644 --- a/internal/commands/bake_test.go +++ b/internal/commands/bake_test.go @@ -96,12 +96,12 @@ var _ = Describe("Bake", func() { return "/home/", nil } - fakeTemplateVariablesService.FromPathsAndPairsReturns(map[string]interface{}{ + fakeTemplateVariablesService.FromPathsAndPairsReturns(map[string]any{ "some-variable-from-file": "some-variable-value-from-file", "some-variable": "some-variable-value", }, nil) - fakeReleasesService.FromDirectoriesReturns(map[string]interface{}{ + fakeReleasesService.FromDirectoriesReturns(map[string]any{ "some-release-1": builder.ReleaseManifest{ Name: "some-release-1", Version: "1.2.3", @@ -119,21 +119,21 @@ var _ = Describe("Bake", func() { OperatingSystem: "an-operating-system", }, nil) - fakeFormsService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakeFormsService.ParseMetadataTemplatesReturns(map[string]any{ "some-form": builder.Metadata{ "name": "some-form", "label": "some-form-label", }, }, nil) - fakeBOSHVariablesService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakeBOSHVariablesService.ParseMetadataTemplatesReturns(map[string]any{ "some-secret": builder.Metadata{ "name": "some-secret", "type": "password", }, }, nil) - fakeInstanceGroupsService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakeInstanceGroupsService.ParseMetadataTemplatesReturns(map[string]any{ "some-instance-group": builder.Metadata{ "name": "some-instance-group", "manifest": "some-manifest", @@ -142,7 +142,7 @@ var _ = Describe("Bake", func() { }, }, nil) - fakeJobsService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakeJobsService.ParseMetadataTemplatesReturns(map[string]any{ "some-job": builder.Metadata{ "name": "some-job", "release": "some-release", @@ -150,7 +150,7 @@ var _ = Describe("Bake", func() { }, }, nil) - fakePropertiesService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakePropertiesService.ParseMetadataTemplatesReturns(map[string]any{ "some-property": builder.Metadata{ "name": "some-property", "type": "boolean", @@ -159,7 +159,7 @@ var _ = Describe("Bake", func() { }, }, nil) - fakeRuntimeConfigsService.ParseMetadataTemplatesReturns(map[string]interface{}{ + fakeRuntimeConfigsService.ParseMetadataTemplatesReturns(map[string]any{ "some-runtime-config": builder.Metadata{ "name": "some-runtime-config", "runtime_config": "some-addon-runtime-config", @@ -265,17 +265,17 @@ var _ = Describe("Bake", func() { input.MetadataGitSHA = nil // func pointers are not comparable unless they are both nil Expect(input).To(Equal(builder.InterpolateInput{ Version: "1.2.3", - BOSHVariables: map[string]interface{}{ + BOSHVariables: map[string]any{ "some-secret": builder.Metadata{ "name": "some-secret", "type": "password", }, }, - Variables: map[string]interface{}{ + Variables: map[string]any{ "some-variable-from-file": "some-variable-value-from-file", "some-variable": "some-variable-value", }, - ReleaseManifests: map[string]interface{}{ + ReleaseManifests: map[string]any{ "some-release-1": builder.ReleaseManifest{ Name: "some-release-1", Version: "1.2.3", @@ -291,14 +291,14 @@ var _ = Describe("Bake", func() { Version: "2.3.4", OperatingSystem: "an-operating-system", }, - FormTypes: map[string]interface{}{ + FormTypes: map[string]any{ "some-form": builder.Metadata{ "name": "some-form", "label": "some-form-label", }, }, IconImage: "some-encoded-icon", - InstanceGroups: map[string]interface{}{ + InstanceGroups: map[string]any{ "some-instance-group": builder.Metadata{ "name": "some-instance-group", "manifest": "some-manifest", @@ -306,14 +306,14 @@ var _ = Describe("Bake", func() { "release": "some-release", }, }, - Jobs: map[string]interface{}{ + Jobs: map[string]any{ "some-job": builder.Metadata{ "name": "some-job", "release": "some-release", "consumes": "some-link", }, }, - PropertyBlueprints: map[string]interface{}{ + PropertyBlueprints: map[string]any{ "some-property": builder.Metadata{ "name": "some-property", "type": "boolean", @@ -321,7 +321,7 @@ var _ = Describe("Bake", func() { "default": false, }, }, - RuntimeConfigs: map[string]interface{}{ + RuntimeConfigs: map[string]any{ "some-runtime-config": builder.Metadata{ "name": "some-runtime-config", "runtime_config": "some-addon-runtime-config", diff --git a/internal/commands/fakes/from_directories.go b/internal/commands/fakes/from_directories.go index 2d63a2bca..40b0a9fca 100644 --- a/internal/commands/fakes/from_directories.go +++ b/internal/commands/fakes/from_directories.go @@ -6,24 +6,24 @@ import ( ) type FromDirectories struct { - FromDirectoriesStub func([]string) (map[string]interface{}, error) + FromDirectoriesStub func([]string) (map[string]any, error) fromDirectoriesMutex sync.RWMutex fromDirectoriesArgsForCall []struct { arg1 []string } fromDirectoriesReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } fromDirectoriesReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } -func (fake *FromDirectories) FromDirectories(arg1 []string) (map[string]interface{}, error) { +func (fake *FromDirectories) FromDirectories(arg1 []string) (map[string]any, error) { var arg1Copy []string if arg1 != nil { arg1Copy = make([]string, len(arg1)) @@ -53,7 +53,7 @@ func (fake *FromDirectories) FromDirectoriesCallCount() int { return len(fake.fromDirectoriesArgsForCall) } -func (fake *FromDirectories) FromDirectoriesCalls(stub func([]string) (map[string]interface{}, error)) { +func (fake *FromDirectories) FromDirectoriesCalls(stub func([]string) (map[string]any, error)) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = stub @@ -66,28 +66,28 @@ func (fake *FromDirectories) FromDirectoriesArgsForCall(i int) []string { return argsForCall.arg1 } -func (fake *FromDirectories) FromDirectoriesReturns(result1 map[string]interface{}, result2 error) { +func (fake *FromDirectories) FromDirectoriesReturns(result1 map[string]any, result2 error) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = nil fake.fromDirectoriesReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *FromDirectories) FromDirectoriesReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *FromDirectories) FromDirectoriesReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = nil if fake.fromDirectoriesReturnsOnCall == nil { fake.fromDirectoriesReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.fromDirectoriesReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } diff --git a/internal/commands/fakes/parse_metadata_templates.go b/internal/commands/fakes/parse_metadata_templates.go index 07374f53e..d32147dd9 100644 --- a/internal/commands/fakes/parse_metadata_templates.go +++ b/internal/commands/fakes/parse_metadata_templates.go @@ -6,25 +6,25 @@ import ( ) type MetadataTemplatesParser struct { - ParseMetadataTemplatesStub func([]string, map[string]interface{}) (map[string]interface{}, error) + ParseMetadataTemplatesStub func([]string, map[string]any) (map[string]any, error) parseMetadataTemplatesMutex sync.RWMutex parseMetadataTemplatesArgsForCall []struct { arg1 []string - arg2 map[string]interface{} + arg2 map[string]any } parseMetadataTemplatesReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } parseMetadataTemplatesReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } -func (fake *MetadataTemplatesParser) ParseMetadataTemplates(arg1 []string, arg2 map[string]interface{}) (map[string]interface{}, error) { +func (fake *MetadataTemplatesParser) ParseMetadataTemplates(arg1 []string, arg2 map[string]any) (map[string]any, error) { var arg1Copy []string if arg1 != nil { arg1Copy = make([]string, len(arg1)) @@ -34,7 +34,7 @@ func (fake *MetadataTemplatesParser) ParseMetadataTemplates(arg1 []string, arg2 ret, specificReturn := fake.parseMetadataTemplatesReturnsOnCall[len(fake.parseMetadataTemplatesArgsForCall)] fake.parseMetadataTemplatesArgsForCall = append(fake.parseMetadataTemplatesArgsForCall, struct { arg1 []string - arg2 map[string]interface{} + arg2 map[string]any }{arg1Copy, arg2}) stub := fake.ParseMetadataTemplatesStub fakeReturns := fake.parseMetadataTemplatesReturns @@ -55,41 +55,41 @@ func (fake *MetadataTemplatesParser) ParseMetadataTemplatesCallCount() int { return len(fake.parseMetadataTemplatesArgsForCall) } -func (fake *MetadataTemplatesParser) ParseMetadataTemplatesCalls(stub func([]string, map[string]interface{}) (map[string]interface{}, error)) { +func (fake *MetadataTemplatesParser) ParseMetadataTemplatesCalls(stub func([]string, map[string]any) (map[string]any, error)) { fake.parseMetadataTemplatesMutex.Lock() defer fake.parseMetadataTemplatesMutex.Unlock() fake.ParseMetadataTemplatesStub = stub } -func (fake *MetadataTemplatesParser) ParseMetadataTemplatesArgsForCall(i int) ([]string, map[string]interface{}) { +func (fake *MetadataTemplatesParser) ParseMetadataTemplatesArgsForCall(i int) ([]string, map[string]any) { fake.parseMetadataTemplatesMutex.RLock() defer fake.parseMetadataTemplatesMutex.RUnlock() argsForCall := fake.parseMetadataTemplatesArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } -func (fake *MetadataTemplatesParser) ParseMetadataTemplatesReturns(result1 map[string]interface{}, result2 error) { +func (fake *MetadataTemplatesParser) ParseMetadataTemplatesReturns(result1 map[string]any, result2 error) { fake.parseMetadataTemplatesMutex.Lock() defer fake.parseMetadataTemplatesMutex.Unlock() fake.ParseMetadataTemplatesStub = nil fake.parseMetadataTemplatesReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *MetadataTemplatesParser) ParseMetadataTemplatesReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *MetadataTemplatesParser) ParseMetadataTemplatesReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.parseMetadataTemplatesMutex.Lock() defer fake.parseMetadataTemplatesMutex.Unlock() fake.ParseMetadataTemplatesStub = nil if fake.parseMetadataTemplatesReturnsOnCall == nil { fake.parseMetadataTemplatesReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.parseMetadataTemplatesReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } diff --git a/internal/commands/fakes/session_dialer.go b/internal/commands/fakes/session_dialer.go index 41d2c41a3..d085a405e 100644 --- a/internal/commands/fakes/session_dialer.go +++ b/internal/commands/fakes/session_dialer.go @@ -26,7 +26,7 @@ type SessionDialer struct { runReturnsOnCall map[int]struct { result1 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -36,7 +36,7 @@ func (fake *SessionDialer) Allow(arg1 session.Attachable) { arg1 session.Attachable }{arg1}) stub := fake.AllowStub - fake.recordInvocation("Allow", []interface{}{arg1}) + fake.recordInvocation("Allow", []any{arg1}) fake.allowMutex.Unlock() if stub != nil { fake.AllowStub(arg1) @@ -71,7 +71,7 @@ func (fake *SessionDialer) Run(arg1 context.Context, arg2 session.Dialer) error }{arg1, arg2}) stub := fake.RunStub fakeReturns := fake.runReturns - fake.recordInvocation("Run", []interface{}{arg1, arg2}) + fake.recordInvocation("Run", []any{arg1, arg2}) fake.runMutex.Unlock() if stub != nil { return stub(arg1, arg2) @@ -124,28 +124,28 @@ func (fake *SessionDialer) RunReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *SessionDialer) Invocations() map[string][][]interface{} { +func (fake *SessionDialer) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.allowMutex.RLock() defer fake.allowMutex.RUnlock() fake.runMutex.RLock() defer fake.runMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *SessionDialer) recordInvocation(key string, args []interface{}) { +func (fake *SessionDialer) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/internal/commands/fakes/stemcell_service.go b/internal/commands/fakes/stemcell_service.go index 9634254d8..7aa4e4669 100644 --- a/internal/commands/fakes/stemcell_service.go +++ b/internal/commands/fakes/stemcell_service.go @@ -6,50 +6,50 @@ import ( ) type StemcellService struct { - FromDirectoriesStub func([]string) (map[string]interface{}, error) + FromDirectoriesStub func([]string) (map[string]any, error) fromDirectoriesMutex sync.RWMutex fromDirectoriesArgsForCall []struct { arg1 []string } fromDirectoriesReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } fromDirectoriesReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } - FromKilnfileStub func(string) (map[string]interface{}, error) + FromKilnfileStub func(string) (map[string]any, error) fromKilnfileMutex sync.RWMutex fromKilnfileArgsForCall []struct { arg1 string } fromKilnfileReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } fromKilnfileReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } - FromTarballStub func(string) (interface{}, error) + FromTarballStub func(string) (any, error) fromTarballMutex sync.RWMutex fromTarballArgsForCall []struct { arg1 string } fromTarballReturns struct { - result1 interface{} + result1 any result2 error } fromTarballReturnsOnCall map[int]struct { - result1 interface{} + result1 any result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } -func (fake *StemcellService) FromDirectories(arg1 []string) (map[string]interface{}, error) { +func (fake *StemcellService) FromDirectories(arg1 []string) (map[string]any, error) { var arg1Copy []string if arg1 != nil { arg1Copy = make([]string, len(arg1)) @@ -79,7 +79,7 @@ func (fake *StemcellService) FromDirectoriesCallCount() int { return len(fake.fromDirectoriesArgsForCall) } -func (fake *StemcellService) FromDirectoriesCalls(stub func([]string) (map[string]interface{}, error)) { +func (fake *StemcellService) FromDirectoriesCalls(stub func([]string) (map[string]any, error)) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = stub @@ -92,33 +92,33 @@ func (fake *StemcellService) FromDirectoriesArgsForCall(i int) []string { return argsForCall.arg1 } -func (fake *StemcellService) FromDirectoriesReturns(result1 map[string]interface{}, result2 error) { +func (fake *StemcellService) FromDirectoriesReturns(result1 map[string]any, result2 error) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = nil fake.fromDirectoriesReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *StemcellService) FromDirectoriesReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *StemcellService) FromDirectoriesReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.fromDirectoriesMutex.Lock() defer fake.fromDirectoriesMutex.Unlock() fake.FromDirectoriesStub = nil if fake.fromDirectoriesReturnsOnCall == nil { fake.fromDirectoriesReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.fromDirectoriesReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *StemcellService) FromKilnfile(arg1 string) (map[string]interface{}, error) { +func (fake *StemcellService) FromKilnfile(arg1 string) (map[string]any, error) { fake.fromKilnfileMutex.Lock() ret, specificReturn := fake.fromKilnfileReturnsOnCall[len(fake.fromKilnfileArgsForCall)] fake.fromKilnfileArgsForCall = append(fake.fromKilnfileArgsForCall, struct { @@ -143,7 +143,7 @@ func (fake *StemcellService) FromKilnfileCallCount() int { return len(fake.fromKilnfileArgsForCall) } -func (fake *StemcellService) FromKilnfileCalls(stub func(string) (map[string]interface{}, error)) { +func (fake *StemcellService) FromKilnfileCalls(stub func(string) (map[string]any, error)) { fake.fromKilnfileMutex.Lock() defer fake.fromKilnfileMutex.Unlock() fake.FromKilnfileStub = stub @@ -156,33 +156,33 @@ func (fake *StemcellService) FromKilnfileArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *StemcellService) FromKilnfileReturns(result1 map[string]interface{}, result2 error) { +func (fake *StemcellService) FromKilnfileReturns(result1 map[string]any, result2 error) { fake.fromKilnfileMutex.Lock() defer fake.fromKilnfileMutex.Unlock() fake.FromKilnfileStub = nil fake.fromKilnfileReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *StemcellService) FromKilnfileReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *StemcellService) FromKilnfileReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.fromKilnfileMutex.Lock() defer fake.fromKilnfileMutex.Unlock() fake.FromKilnfileStub = nil if fake.fromKilnfileReturnsOnCall == nil { fake.fromKilnfileReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.fromKilnfileReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *StemcellService) FromTarball(arg1 string) (interface{}, error) { +func (fake *StemcellService) FromTarball(arg1 string) (any, error) { fake.fromTarballMutex.Lock() ret, specificReturn := fake.fromTarballReturnsOnCall[len(fake.fromTarballArgsForCall)] fake.fromTarballArgsForCall = append(fake.fromTarballArgsForCall, struct { @@ -207,7 +207,7 @@ func (fake *StemcellService) FromTarballCallCount() int { return len(fake.fromTarballArgsForCall) } -func (fake *StemcellService) FromTarballCalls(stub func(string) (interface{}, error)) { +func (fake *StemcellService) FromTarballCalls(stub func(string) (any, error)) { fake.fromTarballMutex.Lock() defer fake.fromTarballMutex.Unlock() fake.FromTarballStub = stub @@ -220,28 +220,28 @@ func (fake *StemcellService) FromTarballArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *StemcellService) FromTarballReturns(result1 interface{}, result2 error) { +func (fake *StemcellService) FromTarballReturns(result1 any, result2 error) { fake.fromTarballMutex.Lock() defer fake.fromTarballMutex.Unlock() fake.FromTarballStub = nil fake.fromTarballReturns = struct { - result1 interface{} + result1 any result2 error }{result1, result2} } -func (fake *StemcellService) FromTarballReturnsOnCall(i int, result1 interface{}, result2 error) { +func (fake *StemcellService) FromTarballReturnsOnCall(i int, result1 any, result2 error) { fake.fromTarballMutex.Lock() defer fake.fromTarballMutex.Unlock() fake.FromTarballStub = nil if fake.fromTarballReturnsOnCall == nil { fake.fromTarballReturnsOnCall = make(map[int]struct { - result1 interface{} + result1 any result2 error }) } fake.fromTarballReturnsOnCall[i] = struct { - result1 interface{} + result1 any result2 error }{result1, result2} } diff --git a/internal/commands/fakes/template_variables_service.go b/internal/commands/fakes/template_variables_service.go index 49bf03827..087ce59ac 100644 --- a/internal/commands/fakes/template_variables_service.go +++ b/internal/commands/fakes/template_variables_service.go @@ -6,25 +6,25 @@ import ( ) type TemplateVariablesService struct { - FromPathsAndPairsStub func([]string, []string) (map[string]interface{}, error) + FromPathsAndPairsStub func([]string, []string) (map[string]any, error) fromPathsAndPairsMutex sync.RWMutex fromPathsAndPairsArgsForCall []struct { arg1 []string arg2 []string } fromPathsAndPairsReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } fromPathsAndPairsReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } -func (fake *TemplateVariablesService) FromPathsAndPairs(arg1 []string, arg2 []string) (map[string]interface{}, error) { +func (fake *TemplateVariablesService) FromPathsAndPairs(arg1 []string, arg2 []string) (map[string]any, error) { var arg1Copy []string if arg1 != nil { arg1Copy = make([]string, len(arg1)) @@ -60,7 +60,7 @@ func (fake *TemplateVariablesService) FromPathsAndPairsCallCount() int { return len(fake.fromPathsAndPairsArgsForCall) } -func (fake *TemplateVariablesService) FromPathsAndPairsCalls(stub func([]string, []string) (map[string]interface{}, error)) { +func (fake *TemplateVariablesService) FromPathsAndPairsCalls(stub func([]string, []string) (map[string]any, error)) { fake.fromPathsAndPairsMutex.Lock() defer fake.fromPathsAndPairsMutex.Unlock() fake.FromPathsAndPairsStub = stub @@ -73,28 +73,28 @@ func (fake *TemplateVariablesService) FromPathsAndPairsArgsForCall(i int) ([]str return argsForCall.arg1, argsForCall.arg2 } -func (fake *TemplateVariablesService) FromPathsAndPairsReturns(result1 map[string]interface{}, result2 error) { +func (fake *TemplateVariablesService) FromPathsAndPairsReturns(result1 map[string]any, result2 error) { fake.fromPathsAndPairsMutex.Lock() defer fake.fromPathsAndPairsMutex.Unlock() fake.FromPathsAndPairsStub = nil fake.fromPathsAndPairsReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *TemplateVariablesService) FromPathsAndPairsReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *TemplateVariablesService) FromPathsAndPairsReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.fromPathsAndPairsMutex.Lock() defer fake.fromPathsAndPairsMutex.Unlock() fake.FromPathsAndPairsStub = nil if fake.fromPathsAndPairsReturnsOnCall == nil { fake.fromPathsAndPairsReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.fromPathsAndPairsReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } diff --git a/internal/commands/flags/parse.go b/internal/commands/flags/parse.go index b4ce7054b..5e088ebd2 100644 --- a/internal/commands/flags/parse.go +++ b/internal/commands/flags/parse.go @@ -32,7 +32,7 @@ type ( } VariablesService interface { - FromPathsAndPairs(paths []string, pairs []string) (templateVariables map[string]interface{}, err error) + FromPathsAndPairs(paths []string, pairs []string) (templateVariables map[string]any, err error) } ) diff --git a/internal/commands/generate_osm_manifest_test.go b/internal/commands/generate_osm_manifest_test.go index e978da639..7852f73d2 100644 --- a/internal/commands/generate_osm_manifest_test.go +++ b/internal/commands/generate_osm_manifest_test.go @@ -334,7 +334,7 @@ func TestOSM_Execute(t *testing.T) { }) } -func writeYAML(t *testing.T, path string, data interface{}) { +func writeYAML(t *testing.T, path string, data any) { t.Helper() buf, err := yaml.Marshal(data) if err != nil { diff --git a/internal/commands/glaze_test.go b/internal/commands/glaze_test.go index 1f9997dc6..615e98296 100644 --- a/internal/commands/glaze_test.go +++ b/internal/commands/glaze_test.go @@ -187,7 +187,7 @@ func TestGlaze_Execute(t *testing.T) { }) } -func writeYAML(t *testing.T, path string, data interface{}) { +func writeYAML(t *testing.T, path string, data any) { t.Helper() buf, err := yaml.Marshal(data) if err != nil { @@ -206,7 +206,7 @@ func writeYAML(t *testing.T, path string, data interface{}) { } } -func readYAML(t *testing.T, path string, data interface{}) { +func readYAML(t *testing.T, path string, data any) { t.Helper() buf, err := os.ReadFile(path) diff --git a/internal/commands/init_test.go b/internal/commands/init_test.go index 8bdb5fcf0..0d0808000 100644 --- a/internal/commands/init_test.go +++ b/internal/commands/init_test.go @@ -26,7 +26,7 @@ type command interface { var _ command -func fsWriteYAML(fs billy.Basic, path string, data interface{}) error { +func fsWriteYAML(fs billy.Basic, path string, data any) error { buf, err := yaml.Marshal(data) if err != nil { return err @@ -42,7 +42,7 @@ func fsWriteYAML(fs billy.Basic, path string, data interface{}) error { return err } -func fsReadYAML(fs billy.Basic, path string, data interface{}) error { +func fsReadYAML(fs billy.Basic, path string, data any) error { f, err := fs.Open(path) if err != nil { return nil diff --git a/internal/commands/test_tile_test.go b/internal/commands/test_tile_test.go index 73aa5c3b7..d5630f746 100644 --- a/internal/commands/test_tile_test.go +++ b/internal/commands/test_tile_test.go @@ -345,7 +345,6 @@ var _ = Describe("kiln test docker", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Docker daemon is not running")) }) - }) }) @@ -384,7 +383,7 @@ type testingT interface { Helper() Cleanup(func()) TempDir() string - Fatal(args ...interface{}) + Fatal(args ...any) Name() string } diff --git a/internal/commands/update_stemcell_test.go b/internal/commands/update_stemcell_test.go index 612b6859e..c2ab0df43 100644 --- a/internal/commands/update_stemcell_test.go +++ b/internal/commands/update_stemcell_test.go @@ -430,7 +430,7 @@ var _ = Describe("UpdateStemcell", func() { }) }) -func createYAMLFile(fs billy.Filesystem, fp string, data interface{}) error { +func createYAMLFile(fs billy.Filesystem, fp string, data any) error { f, err := fs.Create(fp) if err != nil { return err diff --git a/internal/component/fakes/release_asset_downloader.go b/internal/component/fakes/release_asset_downloader.go index 1767f53b3..34f9f9bc6 100644 --- a/internal/component/fakes/release_asset_downloader.go +++ b/internal/component/fakes/release_asset_downloader.go @@ -30,7 +30,7 @@ type ReleaseAssetDownloader struct { result2 string result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -46,7 +46,7 @@ func (fake *ReleaseAssetDownloader) DownloadReleaseAsset(arg1 context.Context, a }{arg1, arg2, arg3, arg4, arg5}) stub := fake.DownloadReleaseAssetStub fakeReturns := fake.downloadReleaseAssetReturns - fake.recordInvocation("DownloadReleaseAsset", []interface{}{arg1, arg2, arg3, arg4, arg5}) + fake.recordInvocation("DownloadReleaseAsset", []any{arg1, arg2, arg3, arg4, arg5}) fake.downloadReleaseAssetMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4, arg5) @@ -105,26 +105,26 @@ func (fake *ReleaseAssetDownloader) DownloadReleaseAssetReturnsOnCall(i int, res }{result1, result2, result3} } -func (fake *ReleaseAssetDownloader) Invocations() map[string][][]interface{} { +func (fake *ReleaseAssetDownloader) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.downloadReleaseAssetMutex.RLock() defer fake.downloadReleaseAssetMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *ReleaseAssetDownloader) recordInvocation(key string, args []interface{}) { +func (fake *ReleaseAssetDownloader) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/internal/component/fakes_internal/release_by_tag_getter_asset_downloader.go b/internal/component/fakes_internal/release_by_tag_getter_asset_downloader.go index fade2ea64..b23c72c42 100644 --- a/internal/component/fakes_internal/release_by_tag_getter_asset_downloader.go +++ b/internal/component/fakes_internal/release_by_tag_getter_asset_downloader.go @@ -48,7 +48,7 @@ type ReleaseByTagGetterAssetDownloader struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -64,7 +64,7 @@ func (fake *ReleaseByTagGetterAssetDownloader) DownloadReleaseAsset(arg1 context }{arg1, arg2, arg3, arg4, arg5}) stub := fake.DownloadReleaseAssetStub fakeReturns := fake.downloadReleaseAssetReturns - fake.recordInvocation("DownloadReleaseAsset", []interface{}{arg1, arg2, arg3, arg4, arg5}) + fake.recordInvocation("DownloadReleaseAsset", []any{arg1, arg2, arg3, arg4, arg5}) fake.downloadReleaseAssetMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4, arg5) @@ -134,7 +134,7 @@ func (fake *ReleaseByTagGetterAssetDownloader) GetReleaseByTag(arg1 context.Cont }{arg1, arg2, arg3, arg4}) stub := fake.GetReleaseByTagStub fakeReturns := fake.getReleaseByTagReturns - fake.recordInvocation("GetReleaseByTag", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("GetReleaseByTag", []any{arg1, arg2, arg3, arg4}) fake.getReleaseByTagMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -193,28 +193,28 @@ func (fake *ReleaseByTagGetterAssetDownloader) GetReleaseByTagReturnsOnCall(i in }{result1, result2, result3} } -func (fake *ReleaseByTagGetterAssetDownloader) Invocations() map[string][][]interface{} { +func (fake *ReleaseByTagGetterAssetDownloader) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.downloadReleaseAssetMutex.RLock() defer fake.downloadReleaseAssetMutex.RUnlock() fake.getReleaseByTagMutex.RLock() defer fake.getReleaseByTagMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *ReleaseByTagGetterAssetDownloader) recordInvocation(key string, args []interface{}) { +func (fake *ReleaseByTagGetterAssetDownloader) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/internal/component/fakes_internal/repository_release_lister.go b/internal/component/fakes_internal/repository_release_lister.go index 978856fd3..042e3b89c 100644 --- a/internal/component/fakes_internal/repository_release_lister.go +++ b/internal/component/fakes_internal/repository_release_lister.go @@ -27,7 +27,7 @@ type RepositoryReleaseLister struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -42,7 +42,7 @@ func (fake *RepositoryReleaseLister) ListReleases(arg1 context.Context, arg2 str }{arg1, arg2, arg3, arg4}) stub := fake.ListReleasesStub fakeReturns := fake.listReleasesReturns - fake.recordInvocation("ListReleases", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListReleases", []any{arg1, arg2, arg3, arg4}) fake.listReleasesMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -101,26 +101,26 @@ func (fake *RepositoryReleaseLister) ListReleasesReturnsOnCall(i int, result1 [] }{result1, result2, result3} } -func (fake *RepositoryReleaseLister) Invocations() map[string][][]interface{} { +func (fake *RepositoryReleaseLister) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.listReleasesMutex.RLock() defer fake.listReleasesMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *RepositoryReleaseLister) recordInvocation(key string, args []interface{}) { +func (fake *RepositoryReleaseLister) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/internal/component/release_source_test.go b/internal/component/release_source_test.go index bfa8828b7..caba16a6a 100644 --- a/internal/component/release_source_test.go +++ b/internal/component/release_source_test.go @@ -116,7 +116,7 @@ var _ = Describe("ReleaseSourceList", func() { }) It("panics with a helpful message", func() { - var r interface{} + var r any func() { defer func() { r = recover() diff --git a/internal/component/s3_release_source_test.go b/internal/component/s3_release_source_test.go index e2c259939..c5e03c4ee 100644 --- a/internal/component/s3_release_source_test.go +++ b/internal/component/s3_release_source_test.go @@ -60,7 +60,7 @@ var _ = Describe("S3ReleaseSource", func() { DescribeTable("bad config", func(before func(sourceConfig *cargo.ReleaseSourceConfig), expectedSubstring string) { before(config) - var r interface{} + var r any func() { defer func() { r = recover() diff --git a/pkg/cargo/bosh_release.go b/pkg/cargo/bosh_release.go new file mode 100644 index 000000000..f42eedfb1 --- /dev/null +++ b/pkg/cargo/bosh_release.go @@ -0,0 +1,197 @@ +package cargo + +import ( + "archive/tar" + "archive/zip" + "compress/gzip" + "crypto/sha1" + "encoding/hex" + "fmt" + "hash" + "io" + "io/fs" + "os" + "path" + "strings" + + "github.com/pivotal-cf/kiln/pkg/tile" + + "golang.org/x/exp/slices" + "gopkg.in/yaml.v2" + + "github.com/pivotal-cf/kiln/pkg/proofing" +) + +func ReadBOSHReleaseFromFile(tilePath, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { + f, err := os.Open(tilePath) + if err != nil { + return proofing.Release{}, err + } + defer closeAndIgnoreError(f) + fi, err := f.Stat() + if err != nil { + return proofing.Release{}, err + } + return ReadBOSHReleaseFromZip(f, fi.Size(), releaseName, releaseVersion, releaseTarball) +} + +func ReadBOSHReleaseFromZip(ra io.ReaderAt, zipFileSize int64, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { + zr, err := zip.NewReader(ra, zipFileSize) + if err != nil { + return proofing.Release{}, fmt.Errorf("failed to do open metadata zip reader: %w", err) + } + return ReadBOSHReleaseFromFS(zr, releaseName, releaseVersion, releaseTarball) +} + +func ReadBOSHReleaseFromFS(dir fs.FS, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { + metadataBuf, err := tile.ReadMetadataFromFS(dir) + if err != nil { + return proofing.Release{}, err + } + + var metadata struct { + Releases []proofing.Release `yaml:"releases"` + } + err = yaml.Unmarshal(metadataBuf, &metadata) + if err != nil { + return proofing.Release{}, err + } + + releaseIndex := slices.IndexFunc(metadata.Releases, func(release proofing.Release) bool { + return release.Name == releaseName && release.Version == releaseVersion + }) + if releaseIndex == -1 { + return proofing.Release{}, fmt.Errorf("release not found with %s/%s", releaseName, releaseVersion) + } + release := metadata.Releases[releaseIndex] + + f, err := dir.Open(path.Join("releases", release.File)) + if err != nil { + return proofing.Release{}, err + } + defer closeAndIgnoreError(f) + + _, err = io.Copy(releaseTarball, f) + if err != nil { + return proofing.Release{}, fmt.Errorf("failed to copy release tarball: %w", err) + } + + return release, nil +} + +type BOSHReleasePackage struct { + Name string `yaml:"name"` + Version string `yaml:"version"` + Fingerprint string `yaml:"fingerprint"` + SHA1 string `yaml:"sha1"` + Dependencies []string `yaml:"dependencies"` +} + +type CompiledBOSHReleasePackage struct { + Name string `yaml:"name"` + Version string `yaml:"version"` + Fingerprint string `yaml:"fingerprint"` + SHA1 string `yaml:"sha1"` + Dependencies []string `yaml:"dependencies"` + + Stemcell string `yaml:"stemcell"` +} + +type BOSHReleaseManifest struct { + Name string `yaml:"name,omitempty"` + Version string `yaml:"version,omitempty"` + CommitHash string `yaml:"commit_hash,omitempty"` + UncommittedChanges bool `yaml:"uncommitted_changes"` + + CompiledPackages []CompiledBOSHReleasePackage `yaml:"compiled_packages"` + Packages []BOSHReleasePackage `yaml:"packages"` +} + +func (mf BOSHReleaseManifest) Stemcell() (string, string, bool) { + if len(mf.CompiledPackages) == 0 { + return "", "", false + } + return strings.Cut(mf.CompiledPackages[0].Stemcell, "/") +} + +type BOSHReleaseTarball struct { + Manifest BOSHReleaseManifest + + SHA1 string + FilePath string +} + +func ReadBOSHReleaseManifestsFromTarballs(dir fs.FS, tarballPaths ...string) ([]BOSHReleaseTarball, error) { + results := make([]BOSHReleaseTarball, 0, len(tarballPaths)) + for _, tarballPath := range tarballPaths { + mf, err := openAndProcessFile(dir, tarballPath, ReadProductTemplatePartFromBOSHReleaseTarball) + if err != nil { + return nil, err + } + sha1Checksum, err := openAndProcessFile(dir, tarballPath, calculateChecksum(sha1.New())) + if err != nil { + return nil, err + } + + results = append(results, BOSHReleaseTarball{ + Manifest: mf, + SHA1: sha1Checksum, + FilePath: tarballPath, + }) + } + return slices.Clip(results), nil +} + +func openAndProcessFile[T any](dir fs.FS, fileName string, process func(io.Reader) (T, error)) (T, error) { + file, err := dir.Open(fileName) + if err != nil { + var zero T + return zero, err + } + defer closeAndIgnoreError(file) + return process(file) +} + +func ReadProductTemplatePartFromBOSHReleaseTarball(r io.Reader) (BOSHReleaseManifest, error) { + gzipReader, err := gzip.NewReader(r) + if err != nil { + return BOSHReleaseManifest{}, err + } + tarReader := tar.NewReader(gzipReader) + + for { + header, err := tarReader.Next() + if err != nil { + if err != io.EOF { + return BOSHReleaseManifest{}, err + } + break + } + if path.Base(header.Name) != "release.MF" { + continue + } + releaseMFBuffer, err := io.ReadAll(tarReader) + if err != nil { + return BOSHReleaseManifest{}, err + } + + var releaseMF BOSHReleaseManifest + + if err := yaml.Unmarshal(releaseMFBuffer, &releaseMF); err != nil { + return BOSHReleaseManifest{}, err + } + + return releaseMF, nil + } + return BOSHReleaseManifest{}, fmt.Errorf("failed to find release.MF in tarball") +} + +func calculateChecksum(h hash.Hash) func(r io.Reader) (string, error) { + return func(r io.Reader) (string, error) { + _, err := io.Copy(h, r) + if err != nil { + return "", err + } + return hex.EncodeToString(h.Sum(nil)), nil + } +} diff --git a/pkg/cargo/bosh_release_test.go b/pkg/cargo/bosh_release_test.go new file mode 100644 index 000000000..a88b44051 --- /dev/null +++ b/pkg/cargo/bosh_release_test.go @@ -0,0 +1,165 @@ +package cargo_test + +import ( + "bytes" + "io" + "os" + "path/filepath" + "testing" + + "github.com/pivotal-cf/kiln/pkg/cargo" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/pivotal-cf/kiln/pkg/proofing" + + . "github.com/onsi/gomega" +) + +func TestReadReleaseFromFile(t *testing.T) { + please := NewWithT(t) + + buf := bytes.NewBuffer(nil) + releaseMetadata, err := cargo.ReadBOSHReleaseFromFile(filepath.Join("testdata", "tile-0.1.2.pivotal"), "hello-release", "v0.1.4", buf) + please.Expect(err).NotTo(HaveOccurred()) + + please.Expect(releaseMetadata).To(Equal(proofing.Release{ + File: "hello-release-v0.1.4-ubuntu-xenial-621.256.tgz", + Name: "hello-release", + SHA1: "c471ac6371eb8fc24508b14d9a49a44f9a5ef98c", + Version: "v0.1.4", + })) + + _, err = io.ReadAll(buf) + please.Expect(err).NotTo(HaveOccurred()) +} + +func TestReadBOSHReleaseManifestsFromTarballs(t *testing.T) { + boshReleases, err := cargo.ReadBOSHReleaseManifestsFromTarballs(os.DirFS("testdata"), "bpm-1.1.21-ubuntu-xenial-621.463.tgz", "bpm-1.1.21.tgz") + require.NoError(t, err) + require.Len(t, boshReleases, 2) + assert.Equal(t, "be5b1710f33128f6c864eae1d97effddb94dd3ac", boshReleases[0].SHA1) + assert.Equal(t, "519b78f2f3333a7b9c000bbef325e12a2f36996d", boshReleases[1].SHA1) + assert.Equal(t, "bpm-1.1.21-ubuntu-xenial-621.463.tgz", boshReleases[0].FilePath) + assert.Equal(t, "bpm-1.1.21.tgz", boshReleases[1].FilePath) +} + +func TestReadProductTemplatePartFromBOSHReleaseTarball(t *testing.T) { + t.Run("when the release is compiled", func(t *testing.T) { + f, err := os.Open(filepath.Join("testdata", "bpm-1.1.21-ubuntu-xenial-621.463.tgz")) + require.NoError(t, err) + t.Cleanup(func() { + closeAndIgnoreError(f) + }) + + result, err := cargo.ReadProductTemplatePartFromBOSHReleaseTarball(f) + require.NoError(t, err) + + require.Equal(t, cargo.BOSHReleaseManifest{ + Name: "bpm", + Version: "1.1.21", + CommitHash: "fd88358", UncommittedChanges: false, CompiledPackages: []cargo.CompiledBOSHReleasePackage{ + { + Name: "bpm", + Version: "be375c78c703cea04667ea7cbbc6d024bb391182", + Fingerprint: "be375c78c703cea04667ea7cbbc6d024bb391182", + SHA1: "b67ab0ceb0cab69a170521bb1a77c91a8546ac21", + Dependencies: []string{"golang-1-linux", "bpm-runc", "tini"}, + Stemcell: "ubuntu-xenial/621.463", + }, + { + Name: "test-server", + Version: "12eba471a2c3dddb8547ef03c23a3231d1f62e6c", + Fingerprint: "12eba471a2c3dddb8547ef03c23a3231d1f62e6c", + SHA1: "7ab0c2066c63eb5c5dd2c06d35b73376f4ad9a81", + Dependencies: []string{"golang-1-linux"}, + Stemcell: "ubuntu-xenial/621.463", + }, + { + Name: "bpm-runc", + Version: "464c6e6611f814bd12016156bf3e682486f34672", + Fingerprint: "464c6e6611f814bd12016156bf3e682486f34672", + SHA1: "bacd602ee0830a30c17b7a502aa0021a6739a3ff", + Dependencies: []string{"golang-1-linux"}, + Stemcell: "ubuntu-xenial/621.463", + }, + { + Name: "golang-1-linux", + Version: "2336380dbf01a44020813425f92be34685ce118bf4767406c461771cfef14fc9", + Fingerprint: "2336380dbf01a44020813425f92be34685ce118bf4767406c461771cfef14fc9", + SHA1: "e8dad3e51eeb5f5fb41dd56bbb8a3ec9655bd4f7", + Dependencies: []string{}, + Stemcell: "ubuntu-xenial/621.463", + }, + { + Name: "tini", + Version: "3d7b02f3eeb480b9581bec4a0096dab9ebdfa4bc", + Fingerprint: "3d7b02f3eeb480b9581bec4a0096dab9ebdfa4bc", + SHA1: "347c76d509ad4b82d99bbbb4b291768ff90b0fba", + Dependencies: []string{}, + Stemcell: "ubuntu-xenial/621.463", + }, + }, + }, result) + }) + + t.Run("when the release is not compiled", func(t *testing.T) { + f, err := os.Open(filepath.Join("testdata", "bpm-1.1.21.tgz")) + require.NoError(t, err) + t.Cleanup(func() { + closeAndIgnoreError(f) + }) + + result, err := cargo.ReadProductTemplatePartFromBOSHReleaseTarball(f) + require.NoError(t, err) + + require.Equal(t, cargo.BOSHReleaseManifest{ + Name: "bpm", + Version: "1.1.21", + CommitHash: "fd88358", + UncommittedChanges: false, + Packages: []cargo.BOSHReleasePackage{ + { + Name: "bpm", + Version: "be375c78c703cea04667ea7cbbc6d024bb391182", + Fingerprint: "be375c78c703cea04667ea7cbbc6d024bb391182", + SHA1: "6ae70da9768bd7333b883463e089c65bea44c685", + Dependencies: []string{"golang-1-linux", "bpm-runc", "tini"}, + }, + { + Name: "bpm-runc", + Version: "464c6e6611f814bd12016156bf3e682486f34672", + Fingerprint: "464c6e6611f814bd12016156bf3e682486f34672", + SHA1: "1a141265caca8b61209349efdbd4ecbc3f802526", + Dependencies: []string{"golang-1-linux"}, + }, + { + Name: "golang-1-linux", + Version: "2336380dbf01a44020813425f92be34685ce118bf4767406c461771cfef14fc9", + Fingerprint: "2336380dbf01a44020813425f92be34685ce118bf4767406c461771cfef14fc9", + SHA1: "sha256:c440fd7aa6d179a6891f765c46f69fa2b6cbadd8da3b019a4fb27fc9001a4f1f", + Dependencies: []string{}, + }, + { + Name: "test-server", + Version: "12eba471a2c3dddb8547ef03c23a3231d1f62e6c", + Fingerprint: "12eba471a2c3dddb8547ef03c23a3231d1f62e6c", + SHA1: "28e74c692da08a1c065052d118b6c1324caa6e8b", + Dependencies: []string{"golang-1-linux"}, + }, + { + Name: "tini", + Version: "3d7b02f3eeb480b9581bec4a0096dab9ebdfa4bc", + Fingerprint: "3d7b02f3eeb480b9581bec4a0096dab9ebdfa4bc", + SHA1: "3d16adbc5ed9bc46a46503cd4f12d883a28fa991", + Dependencies: []string{}, + }, + }, + }, result) + }) +} + +func closeAndIgnoreError(c io.Closer) { + _ = c.Close() +} diff --git a/pkg/cargo/files.go b/pkg/cargo/files.go index 014edd1fe..80f753930 100644 --- a/pkg/cargo/files.go +++ b/pkg/cargo/files.go @@ -1,33 +1,63 @@ package cargo import ( + "bytes" + "errors" "fmt" "io" "os" "path/filepath" + "strconv" "strings" + "text/template" - "gopkg.in/yaml.v2" - - "github.com/pivotal-cf/kiln/internal/builder" + "gopkg.in/yaml.v3" ) -func InterpolateAndParseKilnfile(in io.Reader, templateVariables map[string]interface{}) (Kilnfile, error) { +func InterpolateAndParseKilnfile(in io.Reader, templateVariables map[string]any) (Kilnfile, error) { kilnfileYAML, err := io.ReadAll(in) if err != nil { return Kilnfile{}, fmt.Errorf("unable to read Kilnfile: %w", err) } - interpolator := builder.NewInterpolator() - interpolatedMetadata, err := interpolator.Interpolate(builder.InterpolateInput{ - Variables: templateVariables, - }, "Kilnfile", kilnfileYAML) + kilnfileTemplate, err := template.New("Kilnfile"). + Funcs(template.FuncMap{ + "variable": variableTemplateFunction(templateVariables), + }). + Delims("$(", ")"). + Option("missingkey=error"). + Parse(string(kilnfileYAML)) if err != nil { return Kilnfile{}, err } + var buf bytes.Buffer + if err := kilnfileTemplate.Execute(&buf, struct{}{}); err != nil { + return Kilnfile{}, err + } + var kilnfile Kilnfile - return kilnfile, yaml.Unmarshal(interpolatedMetadata, &kilnfile) + return kilnfile, yaml.Unmarshal(buf.Bytes(), &kilnfile) +} + +func variableTemplateFunction(templateVariables map[string]any) func(name string) (string, error) { + return func(name string) (string, error) { + if templateVariables == nil { + return "", errors.New("--variable or --variables-file must be specified") + } + val, ok := templateVariables[name] + if !ok { + return "", fmt.Errorf("could not find variable with key %q", name) + } + switch value := val.(type) { + case string: + return value, nil + case int: + return strconv.Itoa(value), nil + default: + return "", fmt.Errorf("the variables function used to interpolate variables in the Kilnfile only supports int and string values (%q has type %s)", name, value) + } + } } func ResolveKilnfilePath(path string) (string, error) { @@ -99,6 +129,7 @@ func WriteKilnfile(path string, kf Kilnfile) error { } defer closeAndIgnoreError(f) e := yaml.NewEncoder(f) + e.SetIndent(2) defer closeAndIgnoreError(e) return e.Encode(kf) } diff --git a/pkg/cargo/files_test.go b/pkg/cargo/files_test.go index 3e87281c6..f0f1c63ad 100644 --- a/pkg/cargo/files_test.go +++ b/pkg/cargo/files_test.go @@ -18,7 +18,7 @@ import ( func TestInterpolateAndParseKilnfile(t *testing.T) { please := NewWithT(t) - variables := map[string]interface{}{ + variables := map[string]any{ "bucket": "my-bucket", "region": "middle-earth", "path_template": "not-used", @@ -68,7 +68,7 @@ release_sources: path_template: $( variable "path_template" ) ` - variables := map[string]interface{}{ + variables := map[string]any{ "bucket": "my-bucket", "region": "middle-earth", "path_template": "not-used", @@ -108,7 +108,7 @@ release_sources: func TestInterpolateAndParseKilnfile_input_is_not_valid_yaml(t *testing.T) { please := NewWithT(t) - variables := map[string]interface{}{ + variables := map[string]any{ "bucket": "my-bucket", "region": "middle-earth", "path_template": "not-used", @@ -127,7 +127,7 @@ func TestInterpolateAndParseKilnfile_input_is_not_valid_yaml(t *testing.T) { func TestInterpolateAndParseKilnfile_interpolation_variable_not_found(t *testing.T) { please := NewWithT(t) - variables := map[string]interface{}{ + variables := map[string]any{ "bucket": "my-bucket", // "region": "middle-earth", // <- the missing variable "path_template": "not-used", @@ -140,7 +140,7 @@ func TestInterpolateAndParseKilnfile_interpolation_variable_not_found(t *testing strings.NewReader(validKilnfile), variables, ) - please.Expect(err).To(MatchError(ContainSubstring(`could not find variable with key 'region'`))) + please.Expect(err).To(MatchError(ContainSubstring(`could not find variable with key "region"`))) } const validKilnfile = `--- diff --git a/pkg/cargo/testdata/bpm-1.1.21-ubuntu-xenial-621.463.tgz b/pkg/cargo/testdata/bpm-1.1.21-ubuntu-xenial-621.463.tgz new file mode 100644 index 000000000..34266e764 Binary files /dev/null and b/pkg/cargo/testdata/bpm-1.1.21-ubuntu-xenial-621.463.tgz differ diff --git a/pkg/cargo/testdata/bpm-1.1.21.tgz b/pkg/cargo/testdata/bpm-1.1.21.tgz new file mode 100644 index 000000000..40095d7ee Binary files /dev/null and b/pkg/cargo/testdata/bpm-1.1.21.tgz differ diff --git a/pkg/cargo/testdata/tile-0.1.2.pivotal b/pkg/cargo/testdata/tile-0.1.2.pivotal new file mode 100644 index 000000000..4c3f973ab Binary files /dev/null and b/pkg/cargo/testdata/tile-0.1.2.pivotal differ diff --git a/pkg/history/decode.go b/pkg/history/decode.go index 544eeb8b3..9897b15f5 100644 --- a/pkg/history/decode.go +++ b/pkg/history/decode.go @@ -11,7 +11,7 @@ import ( "gopkg.in/yaml.v2" ) -func unmarshalFile(storage storer.EncodedObjectStorer, commitHash plumbing.Hash, data interface{}, filePath string) error { +func unmarshalFile(storage storer.EncodedObjectStorer, commitHash plumbing.Hash, data any, filePath string) error { buf, err := fileAtCommit(storage, commitHash, filePath) if err != nil { return err @@ -19,7 +19,7 @@ func unmarshalFile(storage storer.EncodedObjectStorer, commitHash plumbing.Hash, return decodeFile(buf, filePath, data) } -//func readDataFromTree(tree *object.Tree, data interface{}, names []string) error { +//func readDataFromTree(tree *object.Tree, data any, names []string) error { // buf, fileName, err := readBytesFromTree(tree, names) // if err != nil { // return err @@ -27,7 +27,7 @@ func unmarshalFile(storage storer.EncodedObjectStorer, commitHash plumbing.Hash, // return decodeFile(buf, fileName, data) //} -func decodeFile(buf []byte, fileName string, data interface{}) error { +func decodeFile(buf []byte, fileName string, data any) error { if filepath.Base(fileName) == "Kilnfile" { return yaml.Unmarshal(buf, data) } diff --git a/pkg/notes/fakes/historic_kilnfile.go b/pkg/notes/fakes/historic_kilnfile.go new file mode 100644 index 000000000..8a05a0452 --- /dev/null +++ b/pkg/notes/fakes/historic_kilnfile.go @@ -0,0 +1,124 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "sync" + + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/storer" + "github.com/pivotal-cf/kiln/pkg/cargo" +) + +type HistoricKilnfile struct { + Stub func(storer.EncodedObjectStorer, plumbing.Hash, string) (cargo.Kilnfile, cargo.KilnfileLock, error) + mutex sync.RWMutex + argsForCall []struct { + arg1 storer.EncodedObjectStorer + arg2 plumbing.Hash + arg3 string + } + returns struct { + result1 cargo.Kilnfile + result2 cargo.KilnfileLock + result3 error + } + returnsOnCall map[int]struct { + result1 cargo.Kilnfile + result2 cargo.KilnfileLock + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *HistoricKilnfile) Spy(arg1 storer.EncodedObjectStorer, arg2 plumbing.Hash, arg3 string) (cargo.Kilnfile, cargo.KilnfileLock, error) { + fake.mutex.Lock() + ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] + fake.argsForCall = append(fake.argsForCall, struct { + arg1 storer.EncodedObjectStorer + arg2 plumbing.Hash + arg3 string + }{arg1, arg2, arg3}) + stub := fake.Stub + returns := fake.returns + fake.recordInvocation("historicKilnfile", []interface{}{arg1, arg2, arg3}) + fake.mutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return returns.result1, returns.result2, returns.result3 +} + +func (fake *HistoricKilnfile) CallCount() int { + fake.mutex.RLock() + defer fake.mutex.RUnlock() + return len(fake.argsForCall) +} + +func (fake *HistoricKilnfile) Calls(stub func(storer.EncodedObjectStorer, plumbing.Hash, string) (cargo.Kilnfile, cargo.KilnfileLock, error)) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = stub +} + +func (fake *HistoricKilnfile) ArgsForCall(i int) (storer.EncodedObjectStorer, plumbing.Hash, string) { + fake.mutex.RLock() + defer fake.mutex.RUnlock() + return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2, fake.argsForCall[i].arg3 +} + +func (fake *HistoricKilnfile) Returns(result1 cargo.Kilnfile, result2 cargo.KilnfileLock, result3 error) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = nil + fake.returns = struct { + result1 cargo.Kilnfile + result2 cargo.KilnfileLock + result3 error + }{result1, result2, result3} +} + +func (fake *HistoricKilnfile) ReturnsOnCall(i int, result1 cargo.Kilnfile, result2 cargo.KilnfileLock, result3 error) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = nil + if fake.returnsOnCall == nil { + fake.returnsOnCall = make(map[int]struct { + result1 cargo.Kilnfile + result2 cargo.KilnfileLock + result3 error + }) + } + fake.returnsOnCall[i] = struct { + result1 cargo.Kilnfile + result2 cargo.KilnfileLock + result3 error + }{result1, result2, result3} +} + +func (fake *HistoricKilnfile) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.mutex.RLock() + defer fake.mutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *HistoricKilnfile) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/historic_version.go b/pkg/notes/fakes/historic_version.go new file mode 100644 index 000000000..b3d47fb2e --- /dev/null +++ b/pkg/notes/fakes/historic_version.go @@ -0,0 +1,118 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "sync" + + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/storer" +) + +type HistoricVersion struct { + Stub func(storer.EncodedObjectStorer, plumbing.Hash, string) (string, error) + mutex sync.RWMutex + argsForCall []struct { + arg1 storer.EncodedObjectStorer + arg2 plumbing.Hash + arg3 string + } + returns struct { + result1 string + result2 error + } + returnsOnCall map[int]struct { + result1 string + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *HistoricVersion) Spy(arg1 storer.EncodedObjectStorer, arg2 plumbing.Hash, arg3 string) (string, error) { + fake.mutex.Lock() + ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)] + fake.argsForCall = append(fake.argsForCall, struct { + arg1 storer.EncodedObjectStorer + arg2 plumbing.Hash + arg3 string + }{arg1, arg2, arg3}) + stub := fake.Stub + returns := fake.returns + fake.recordInvocation("historicVersion", []interface{}{arg1, arg2, arg3}) + fake.mutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return returns.result1, returns.result2 +} + +func (fake *HistoricVersion) CallCount() int { + fake.mutex.RLock() + defer fake.mutex.RUnlock() + return len(fake.argsForCall) +} + +func (fake *HistoricVersion) Calls(stub func(storer.EncodedObjectStorer, plumbing.Hash, string) (string, error)) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = stub +} + +func (fake *HistoricVersion) ArgsForCall(i int) (storer.EncodedObjectStorer, plumbing.Hash, string) { + fake.mutex.RLock() + defer fake.mutex.RUnlock() + return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2, fake.argsForCall[i].arg3 +} + +func (fake *HistoricVersion) Returns(result1 string, result2 error) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = nil + fake.returns = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *HistoricVersion) ReturnsOnCall(i int, result1 string, result2 error) { + fake.mutex.Lock() + defer fake.mutex.Unlock() + fake.Stub = nil + if fake.returnsOnCall == nil { + fake.returnsOnCall = make(map[int]struct { + result1 string + result2 error + }) + } + fake.returnsOnCall[i] = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *HistoricVersion) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.mutex.RLock() + defer fake.mutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *HistoricVersion) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/issue_getter.go b/pkg/notes/fakes/issue_getter.go new file mode 100644 index 000000000..3dbaa90cc --- /dev/null +++ b/pkg/notes/fakes/issue_getter.go @@ -0,0 +1,126 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "context" + "sync" + + "github.com/google/go-github/v40/github" +) + +type IssueGetter struct { + GetStub func(context.Context, string, string, int) (*github.Issue, *github.Response, error) + getMutex sync.RWMutex + getArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 int + } + getReturns struct { + result1 *github.Issue + result2 *github.Response + result3 error + } + getReturnsOnCall map[int]struct { + result1 *github.Issue + result2 *github.Response + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *IssueGetter) Get(arg1 context.Context, arg2 string, arg3 string, arg4 int) (*github.Issue, *github.Response, error) { + fake.getMutex.Lock() + ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)] + fake.getArgsForCall = append(fake.getArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 int + }{arg1, arg2, arg3, arg4}) + stub := fake.GetStub + fakeReturns := fake.getReturns + fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3, arg4}) + fake.getMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *IssueGetter) GetCallCount() int { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + return len(fake.getArgsForCall) +} + +func (fake *IssueGetter) GetCalls(stub func(context.Context, string, string, int) (*github.Issue, *github.Response, error)) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = stub +} + +func (fake *IssueGetter) GetArgsForCall(i int) (context.Context, string, string, int) { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + argsForCall := fake.getArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *IssueGetter) GetReturns(result1 *github.Issue, result2 *github.Response, result3 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + fake.getReturns = struct { + result1 *github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssueGetter) GetReturnsOnCall(i int, result1 *github.Issue, result2 *github.Response, result3 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + if fake.getReturnsOnCall == nil { + fake.getReturnsOnCall = make(map[int]struct { + result1 *github.Issue + result2 *github.Response + result3 error + }) + } + fake.getReturnsOnCall[i] = struct { + result1 *github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssueGetter) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *IssueGetter) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/issues_by_repo_lister.go b/pkg/notes/fakes/issues_by_repo_lister.go new file mode 100644 index 000000000..f63c2368d --- /dev/null +++ b/pkg/notes/fakes/issues_by_repo_lister.go @@ -0,0 +1,126 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "context" + "sync" + + "github.com/google/go-github/v40/github" +) + +type IssuesByRepoLister struct { + ListByRepoStub func(context.Context, string, string, *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) + listByRepoMutex sync.RWMutex + listByRepoArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.IssueListByRepoOptions + } + listByRepoReturns struct { + result1 []*github.Issue + result2 *github.Response + result3 error + } + listByRepoReturnsOnCall map[int]struct { + result1 []*github.Issue + result2 *github.Response + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *IssuesByRepoLister) ListByRepo(arg1 context.Context, arg2 string, arg3 string, arg4 *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) { + fake.listByRepoMutex.Lock() + ret, specificReturn := fake.listByRepoReturnsOnCall[len(fake.listByRepoArgsForCall)] + fake.listByRepoArgsForCall = append(fake.listByRepoArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.IssueListByRepoOptions + }{arg1, arg2, arg3, arg4}) + stub := fake.ListByRepoStub + fakeReturns := fake.listByRepoReturns + fake.recordInvocation("ListByRepo", []interface{}{arg1, arg2, arg3, arg4}) + fake.listByRepoMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *IssuesByRepoLister) ListByRepoCallCount() int { + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + return len(fake.listByRepoArgsForCall) +} + +func (fake *IssuesByRepoLister) ListByRepoCalls(stub func(context.Context, string, string, *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error)) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = stub +} + +func (fake *IssuesByRepoLister) ListByRepoArgsForCall(i int) (context.Context, string, string, *github.IssueListByRepoOptions) { + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + argsForCall := fake.listByRepoArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *IssuesByRepoLister) ListByRepoReturns(result1 []*github.Issue, result2 *github.Response, result3 error) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = nil + fake.listByRepoReturns = struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesByRepoLister) ListByRepoReturnsOnCall(i int, result1 []*github.Issue, result2 *github.Response, result3 error) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = nil + if fake.listByRepoReturnsOnCall == nil { + fake.listByRepoReturnsOnCall = make(map[int]struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }) + } + fake.listByRepoReturnsOnCall[i] = struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesByRepoLister) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *IssuesByRepoLister) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/issues_service.go b/pkg/notes/fakes/issues_service.go new file mode 100644 index 000000000..fb4af88f0 --- /dev/null +++ b/pkg/notes/fakes/issues_service.go @@ -0,0 +1,306 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "context" + "sync" + + "github.com/google/go-github/v40/github" +) + +type IssuesService struct { + GetStub func(context.Context, string, string, int) (*github.Issue, *github.Response, error) + getMutex sync.RWMutex + getArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 int + } + getReturns struct { + result1 *github.Issue + result2 *github.Response + result3 error + } + getReturnsOnCall map[int]struct { + result1 *github.Issue + result2 *github.Response + result3 error + } + ListByRepoStub func(context.Context, string, string, *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) + listByRepoMutex sync.RWMutex + listByRepoArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.IssueListByRepoOptions + } + listByRepoReturns struct { + result1 []*github.Issue + result2 *github.Response + result3 error + } + listByRepoReturnsOnCall map[int]struct { + result1 []*github.Issue + result2 *github.Response + result3 error + } + ListMilestonesStub func(context.Context, string, string, *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error) + listMilestonesMutex sync.RWMutex + listMilestonesArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.MilestoneListOptions + } + listMilestonesReturns struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + } + listMilestonesReturnsOnCall map[int]struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *IssuesService) Get(arg1 context.Context, arg2 string, arg3 string, arg4 int) (*github.Issue, *github.Response, error) { + fake.getMutex.Lock() + ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)] + fake.getArgsForCall = append(fake.getArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 int + }{arg1, arg2, arg3, arg4}) + stub := fake.GetStub + fakeReturns := fake.getReturns + fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3, arg4}) + fake.getMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *IssuesService) GetCallCount() int { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + return len(fake.getArgsForCall) +} + +func (fake *IssuesService) GetCalls(stub func(context.Context, string, string, int) (*github.Issue, *github.Response, error)) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = stub +} + +func (fake *IssuesService) GetArgsForCall(i int) (context.Context, string, string, int) { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + argsForCall := fake.getArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *IssuesService) GetReturns(result1 *github.Issue, result2 *github.Response, result3 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + fake.getReturns = struct { + result1 *github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) GetReturnsOnCall(i int, result1 *github.Issue, result2 *github.Response, result3 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + if fake.getReturnsOnCall == nil { + fake.getReturnsOnCall = make(map[int]struct { + result1 *github.Issue + result2 *github.Response + result3 error + }) + } + fake.getReturnsOnCall[i] = struct { + result1 *github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) ListByRepo(arg1 context.Context, arg2 string, arg3 string, arg4 *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) { + fake.listByRepoMutex.Lock() + ret, specificReturn := fake.listByRepoReturnsOnCall[len(fake.listByRepoArgsForCall)] + fake.listByRepoArgsForCall = append(fake.listByRepoArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.IssueListByRepoOptions + }{arg1, arg2, arg3, arg4}) + stub := fake.ListByRepoStub + fakeReturns := fake.listByRepoReturns + fake.recordInvocation("ListByRepo", []interface{}{arg1, arg2, arg3, arg4}) + fake.listByRepoMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *IssuesService) ListByRepoCallCount() int { + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + return len(fake.listByRepoArgsForCall) +} + +func (fake *IssuesService) ListByRepoCalls(stub func(context.Context, string, string, *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error)) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = stub +} + +func (fake *IssuesService) ListByRepoArgsForCall(i int) (context.Context, string, string, *github.IssueListByRepoOptions) { + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + argsForCall := fake.listByRepoArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *IssuesService) ListByRepoReturns(result1 []*github.Issue, result2 *github.Response, result3 error) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = nil + fake.listByRepoReturns = struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) ListByRepoReturnsOnCall(i int, result1 []*github.Issue, result2 *github.Response, result3 error) { + fake.listByRepoMutex.Lock() + defer fake.listByRepoMutex.Unlock() + fake.ListByRepoStub = nil + if fake.listByRepoReturnsOnCall == nil { + fake.listByRepoReturnsOnCall = make(map[int]struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }) + } + fake.listByRepoReturnsOnCall[i] = struct { + result1 []*github.Issue + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) ListMilestones(arg1 context.Context, arg2 string, arg3 string, arg4 *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error) { + fake.listMilestonesMutex.Lock() + ret, specificReturn := fake.listMilestonesReturnsOnCall[len(fake.listMilestonesArgsForCall)] + fake.listMilestonesArgsForCall = append(fake.listMilestonesArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.MilestoneListOptions + }{arg1, arg2, arg3, arg4}) + stub := fake.ListMilestonesStub + fakeReturns := fake.listMilestonesReturns + fake.recordInvocation("ListMilestones", []interface{}{arg1, arg2, arg3, arg4}) + fake.listMilestonesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *IssuesService) ListMilestonesCallCount() int { + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + return len(fake.listMilestonesArgsForCall) +} + +func (fake *IssuesService) ListMilestonesCalls(stub func(context.Context, string, string, *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error)) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = stub +} + +func (fake *IssuesService) ListMilestonesArgsForCall(i int) (context.Context, string, string, *github.MilestoneListOptions) { + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + argsForCall := fake.listMilestonesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *IssuesService) ListMilestonesReturns(result1 []*github.Milestone, result2 *github.Response, result3 error) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = nil + fake.listMilestonesReturns = struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) ListMilestonesReturnsOnCall(i int, result1 []*github.Milestone, result2 *github.Response, result3 error) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = nil + if fake.listMilestonesReturnsOnCall == nil { + fake.listMilestonesReturnsOnCall = make(map[int]struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }) + } + fake.listMilestonesReturnsOnCall[i] = struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *IssuesService) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + fake.listByRepoMutex.RLock() + defer fake.listByRepoMutex.RUnlock() + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *IssuesService) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/milestone_lister.go b/pkg/notes/fakes/milestone_lister.go new file mode 100644 index 000000000..02d2c029d --- /dev/null +++ b/pkg/notes/fakes/milestone_lister.go @@ -0,0 +1,126 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "context" + "sync" + + "github.com/google/go-github/v40/github" +) + +type MilestoneLister struct { + ListMilestonesStub func(context.Context, string, string, *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error) + listMilestonesMutex sync.RWMutex + listMilestonesArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.MilestoneListOptions + } + listMilestonesReturns struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + } + listMilestonesReturnsOnCall map[int]struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *MilestoneLister) ListMilestones(arg1 context.Context, arg2 string, arg3 string, arg4 *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error) { + fake.listMilestonesMutex.Lock() + ret, specificReturn := fake.listMilestonesReturnsOnCall[len(fake.listMilestonesArgsForCall)] + fake.listMilestonesArgsForCall = append(fake.listMilestonesArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.MilestoneListOptions + }{arg1, arg2, arg3, arg4}) + stub := fake.ListMilestonesStub + fakeReturns := fake.listMilestonesReturns + fake.recordInvocation("ListMilestones", []interface{}{arg1, arg2, arg3, arg4}) + fake.listMilestonesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *MilestoneLister) ListMilestonesCallCount() int { + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + return len(fake.listMilestonesArgsForCall) +} + +func (fake *MilestoneLister) ListMilestonesCalls(stub func(context.Context, string, string, *github.MilestoneListOptions) ([]*github.Milestone, *github.Response, error)) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = stub +} + +func (fake *MilestoneLister) ListMilestonesArgsForCall(i int) (context.Context, string, string, *github.MilestoneListOptions) { + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + argsForCall := fake.listMilestonesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *MilestoneLister) ListMilestonesReturns(result1 []*github.Milestone, result2 *github.Response, result3 error) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = nil + fake.listMilestonesReturns = struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *MilestoneLister) ListMilestonesReturnsOnCall(i int, result1 []*github.Milestone, result2 *github.Response, result3 error) { + fake.listMilestonesMutex.Lock() + defer fake.listMilestonesMutex.Unlock() + fake.ListMilestonesStub = nil + if fake.listMilestonesReturnsOnCall == nil { + fake.listMilestonesReturnsOnCall = make(map[int]struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }) + } + fake.listMilestonesReturnsOnCall[i] = struct { + result1 []*github.Milestone + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *MilestoneLister) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.listMilestonesMutex.RLock() + defer fake.listMilestonesMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *MilestoneLister) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/fakes/releases_service.go b/pkg/notes/fakes/releases_service.go new file mode 100644 index 000000000..0d89fd752 --- /dev/null +++ b/pkg/notes/fakes/releases_service.go @@ -0,0 +1,129 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "context" + "sync" + + "github.com/google/go-github/v40/github" + "github.com/pivotal-cf/kiln/pkg/cargo" +) + +type ReleaseService struct { + ListReleasesStub func(context.Context, string, string, *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error) + listReleasesMutex sync.RWMutex + listReleasesArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.ListOptions + } + listReleasesReturns struct { + result1 []*github.RepositoryRelease + result2 *github.Response + result3 error + } + listReleasesReturnsOnCall map[int]struct { + result1 []*github.RepositoryRelease + result2 *github.Response + result3 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *ReleaseService) ListReleases(arg1 context.Context, arg2 string, arg3 string, arg4 *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error) { + fake.listReleasesMutex.Lock() + ret, specificReturn := fake.listReleasesReturnsOnCall[len(fake.listReleasesArgsForCall)] + fake.listReleasesArgsForCall = append(fake.listReleasesArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + arg4 *github.ListOptions + }{arg1, arg2, arg3, arg4}) + stub := fake.ListReleasesStub + fakeReturns := fake.listReleasesReturns + fake.recordInvocation("ListReleases", []interface{}{arg1, arg2, arg3, arg4}) + fake.listReleasesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4) + } + if specificReturn { + return ret.result1, ret.result2, ret.result3 + } + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 +} + +func (fake *ReleaseService) ListReleasesCallCount() int { + fake.listReleasesMutex.RLock() + defer fake.listReleasesMutex.RUnlock() + return len(fake.listReleasesArgsForCall) +} + +func (fake *ReleaseService) ListReleasesCalls(stub func(context.Context, string, string, *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error)) { + fake.listReleasesMutex.Lock() + defer fake.listReleasesMutex.Unlock() + fake.ListReleasesStub = stub +} + +func (fake *ReleaseService) ListReleasesArgsForCall(i int) (context.Context, string, string, *github.ListOptions) { + fake.listReleasesMutex.RLock() + defer fake.listReleasesMutex.RUnlock() + argsForCall := fake.listReleasesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *ReleaseService) ListReleasesReturns(result1 []*github.RepositoryRelease, result2 *github.Response, result3 error) { + fake.listReleasesMutex.Lock() + defer fake.listReleasesMutex.Unlock() + fake.ListReleasesStub = nil + fake.listReleasesReturns = struct { + result1 []*github.RepositoryRelease + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *ReleaseService) ListReleasesReturnsOnCall(i int, result1 []*github.RepositoryRelease, result2 *github.Response, result3 error) { + fake.listReleasesMutex.Lock() + defer fake.listReleasesMutex.Unlock() + fake.ListReleasesStub = nil + if fake.listReleasesReturnsOnCall == nil { + fake.listReleasesReturnsOnCall = make(map[int]struct { + result1 []*github.RepositoryRelease + result2 *github.Response + result3 error + }) + } + fake.listReleasesReturnsOnCall[i] = struct { + result1 []*github.RepositoryRelease + result2 *github.Response + result3 error + }{result1, result2, result3} +} + +func (fake *ReleaseService) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.listReleasesMutex.RLock() + defer fake.listReleasesMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *ReleaseService) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ cargo.RepositoryReleaseLister = new(ReleaseService) diff --git a/pkg/notes/fakes/revision_resolver.go b/pkg/notes/fakes/revision_resolver.go new file mode 100644 index 000000000..68269f21a --- /dev/null +++ b/pkg/notes/fakes/revision_resolver.go @@ -0,0 +1,114 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fakes + +import ( + "sync" + + "github.com/go-git/go-git/v5/plumbing" +) + +type RevisionResolver struct { + ResolveRevisionStub func(plumbing.Revision) (*plumbing.Hash, error) + resolveRevisionMutex sync.RWMutex + resolveRevisionArgsForCall []struct { + arg1 plumbing.Revision + } + resolveRevisionReturns struct { + result1 *plumbing.Hash + result2 error + } + resolveRevisionReturnsOnCall map[int]struct { + result1 *plumbing.Hash + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *RevisionResolver) ResolveRevision(arg1 plumbing.Revision) (*plumbing.Hash, error) { + fake.resolveRevisionMutex.Lock() + ret, specificReturn := fake.resolveRevisionReturnsOnCall[len(fake.resolveRevisionArgsForCall)] + fake.resolveRevisionArgsForCall = append(fake.resolveRevisionArgsForCall, struct { + arg1 plumbing.Revision + }{arg1}) + stub := fake.ResolveRevisionStub + fakeReturns := fake.resolveRevisionReturns + fake.recordInvocation("ResolveRevision", []interface{}{arg1}) + fake.resolveRevisionMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *RevisionResolver) ResolveRevisionCallCount() int { + fake.resolveRevisionMutex.RLock() + defer fake.resolveRevisionMutex.RUnlock() + return len(fake.resolveRevisionArgsForCall) +} + +func (fake *RevisionResolver) ResolveRevisionCalls(stub func(plumbing.Revision) (*plumbing.Hash, error)) { + fake.resolveRevisionMutex.Lock() + defer fake.resolveRevisionMutex.Unlock() + fake.ResolveRevisionStub = stub +} + +func (fake *RevisionResolver) ResolveRevisionArgsForCall(i int) plumbing.Revision { + fake.resolveRevisionMutex.RLock() + defer fake.resolveRevisionMutex.RUnlock() + argsForCall := fake.resolveRevisionArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *RevisionResolver) ResolveRevisionReturns(result1 *plumbing.Hash, result2 error) { + fake.resolveRevisionMutex.Lock() + defer fake.resolveRevisionMutex.Unlock() + fake.ResolveRevisionStub = nil + fake.resolveRevisionReturns = struct { + result1 *plumbing.Hash + result2 error + }{result1, result2} +} + +func (fake *RevisionResolver) ResolveRevisionReturnsOnCall(i int, result1 *plumbing.Hash, result2 error) { + fake.resolveRevisionMutex.Lock() + defer fake.resolveRevisionMutex.Unlock() + fake.ResolveRevisionStub = nil + if fake.resolveRevisionReturnsOnCall == nil { + fake.resolveRevisionReturnsOnCall = make(map[int]struct { + result1 *plumbing.Hash + result2 error + }) + } + fake.resolveRevisionReturnsOnCall[i] = struct { + result1 *plumbing.Hash + result2 error + }{result1, result2} +} + +func (fake *RevisionResolver) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.resolveRevisionMutex.RLock() + defer fake.resolveRevisionMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *RevisionResolver) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} diff --git a/pkg/notes/internal/fakes/historic_kilnfile.go b/pkg/notes/internal/fakes/historic_kilnfile.go index 8a05a0452..d687dc660 100644 --- a/pkg/notes/internal/fakes/historic_kilnfile.go +++ b/pkg/notes/internal/fakes/historic_kilnfile.go @@ -27,7 +27,7 @@ type HistoricKilnfile struct { result2 cargo.KilnfileLock result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -41,7 +41,7 @@ func (fake *HistoricKilnfile) Spy(arg1 storer.EncodedObjectStorer, arg2 plumbing }{arg1, arg2, arg3}) stub := fake.Stub returns := fake.returns - fake.recordInvocation("historicKilnfile", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("historicKilnfile", []any{arg1, arg2, arg3}) fake.mutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) @@ -99,26 +99,26 @@ func (fake *HistoricKilnfile) ReturnsOnCall(i int, result1 cargo.Kilnfile, resul }{result1, result2, result3} } -func (fake *HistoricKilnfile) Invocations() map[string][][]interface{} { +func (fake *HistoricKilnfile) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *HistoricKilnfile) recordInvocation(key string, args []interface{}) { +func (fake *HistoricKilnfile) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/historic_version.go b/pkg/notes/internal/fakes/historic_version.go index b3d47fb2e..deb321033 100644 --- a/pkg/notes/internal/fakes/historic_version.go +++ b/pkg/notes/internal/fakes/historic_version.go @@ -24,7 +24,7 @@ type HistoricVersion struct { result1 string result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -38,7 +38,7 @@ func (fake *HistoricVersion) Spy(arg1 storer.EncodedObjectStorer, arg2 plumbing. }{arg1, arg2, arg3}) stub := fake.Stub returns := fake.returns - fake.recordInvocation("historicVersion", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("historicVersion", []any{arg1, arg2, arg3}) fake.mutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) @@ -93,26 +93,26 @@ func (fake *HistoricVersion) ReturnsOnCall(i int, result1 string, result2 error) }{result1, result2} } -func (fake *HistoricVersion) Invocations() map[string][][]interface{} { +func (fake *HistoricVersion) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.mutex.RLock() defer fake.mutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *HistoricVersion) recordInvocation(key string, args []interface{}) { +func (fake *HistoricVersion) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/issue_getter.go b/pkg/notes/internal/fakes/issue_getter.go index 3dbaa90cc..fcd0c6451 100644 --- a/pkg/notes/internal/fakes/issue_getter.go +++ b/pkg/notes/internal/fakes/issue_getter.go @@ -27,7 +27,7 @@ type IssueGetter struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -42,7 +42,7 @@ func (fake *IssueGetter) Get(arg1 context.Context, arg2 string, arg3 string, arg }{arg1, arg2, arg3, arg4}) stub := fake.GetStub fakeReturns := fake.getReturns - fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("Get", []any{arg1, arg2, arg3, arg4}) fake.getMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -101,26 +101,26 @@ func (fake *IssueGetter) GetReturnsOnCall(i int, result1 *github.Issue, result2 }{result1, result2, result3} } -func (fake *IssueGetter) Invocations() map[string][][]interface{} { +func (fake *IssueGetter) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.getMutex.RLock() defer fake.getMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *IssueGetter) recordInvocation(key string, args []interface{}) { +func (fake *IssueGetter) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/issues_by_repo_lister.go b/pkg/notes/internal/fakes/issues_by_repo_lister.go index f63c2368d..af96733bd 100644 --- a/pkg/notes/internal/fakes/issues_by_repo_lister.go +++ b/pkg/notes/internal/fakes/issues_by_repo_lister.go @@ -27,7 +27,7 @@ type IssuesByRepoLister struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -42,7 +42,7 @@ func (fake *IssuesByRepoLister) ListByRepo(arg1 context.Context, arg2 string, ar }{arg1, arg2, arg3, arg4}) stub := fake.ListByRepoStub fakeReturns := fake.listByRepoReturns - fake.recordInvocation("ListByRepo", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListByRepo", []any{arg1, arg2, arg3, arg4}) fake.listByRepoMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -101,26 +101,26 @@ func (fake *IssuesByRepoLister) ListByRepoReturnsOnCall(i int, result1 []*github }{result1, result2, result3} } -func (fake *IssuesByRepoLister) Invocations() map[string][][]interface{} { +func (fake *IssuesByRepoLister) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.listByRepoMutex.RLock() defer fake.listByRepoMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *IssuesByRepoLister) recordInvocation(key string, args []interface{}) { +func (fake *IssuesByRepoLister) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/issues_service.go b/pkg/notes/internal/fakes/issues_service.go index fb4af88f0..0b902787b 100644 --- a/pkg/notes/internal/fakes/issues_service.go +++ b/pkg/notes/internal/fakes/issues_service.go @@ -63,7 +63,7 @@ type IssuesService struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -78,7 +78,7 @@ func (fake *IssuesService) Get(arg1 context.Context, arg2 string, arg3 string, a }{arg1, arg2, arg3, arg4}) stub := fake.GetStub fakeReturns := fake.getReturns - fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("Get", []any{arg1, arg2, arg3, arg4}) fake.getMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -148,7 +148,7 @@ func (fake *IssuesService) ListByRepo(arg1 context.Context, arg2 string, arg3 st }{arg1, arg2, arg3, arg4}) stub := fake.ListByRepoStub fakeReturns := fake.listByRepoReturns - fake.recordInvocation("ListByRepo", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListByRepo", []any{arg1, arg2, arg3, arg4}) fake.listByRepoMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -218,7 +218,7 @@ func (fake *IssuesService) ListMilestones(arg1 context.Context, arg2 string, arg }{arg1, arg2, arg3, arg4}) stub := fake.ListMilestonesStub fakeReturns := fake.listMilestonesReturns - fake.recordInvocation("ListMilestones", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListMilestones", []any{arg1, arg2, arg3, arg4}) fake.listMilestonesMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -277,7 +277,7 @@ func (fake *IssuesService) ListMilestonesReturnsOnCall(i int, result1 []*github. }{result1, result2, result3} } -func (fake *IssuesService) Invocations() map[string][][]interface{} { +func (fake *IssuesService) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.getMutex.RLock() @@ -286,21 +286,21 @@ func (fake *IssuesService) Invocations() map[string][][]interface{} { defer fake.listByRepoMutex.RUnlock() fake.listMilestonesMutex.RLock() defer fake.listMilestonesMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *IssuesService) recordInvocation(key string, args []interface{}) { +func (fake *IssuesService) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/milestone_lister.go b/pkg/notes/internal/fakes/milestone_lister.go index 02d2c029d..ec4389a97 100644 --- a/pkg/notes/internal/fakes/milestone_lister.go +++ b/pkg/notes/internal/fakes/milestone_lister.go @@ -27,7 +27,7 @@ type MilestoneLister struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -42,7 +42,7 @@ func (fake *MilestoneLister) ListMilestones(arg1 context.Context, arg2 string, a }{arg1, arg2, arg3, arg4}) stub := fake.ListMilestonesStub fakeReturns := fake.listMilestonesReturns - fake.recordInvocation("ListMilestones", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListMilestones", []any{arg1, arg2, arg3, arg4}) fake.listMilestonesMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -101,26 +101,26 @@ func (fake *MilestoneLister) ListMilestonesReturnsOnCall(i int, result1 []*githu }{result1, result2, result3} } -func (fake *MilestoneLister) Invocations() map[string][][]interface{} { +func (fake *MilestoneLister) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.listMilestonesMutex.RLock() defer fake.listMilestonesMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *MilestoneLister) recordInvocation(key string, args []interface{}) { +func (fake *MilestoneLister) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/releases_service.go b/pkg/notes/internal/fakes/releases_service.go index 0d89fd752..f97492ca4 100644 --- a/pkg/notes/internal/fakes/releases_service.go +++ b/pkg/notes/internal/fakes/releases_service.go @@ -28,7 +28,7 @@ type ReleaseService struct { result2 *github.Response result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -43,7 +43,7 @@ func (fake *ReleaseService) ListReleases(arg1 context.Context, arg2 string, arg3 }{arg1, arg2, arg3, arg4}) stub := fake.ListReleasesStub fakeReturns := fake.listReleasesReturns - fake.recordInvocation("ListReleases", []interface{}{arg1, arg2, arg3, arg4}) + fake.recordInvocation("ListReleases", []any{arg1, arg2, arg3, arg4}) fake.listReleasesMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3, arg4) @@ -102,26 +102,26 @@ func (fake *ReleaseService) ListReleasesReturnsOnCall(i int, result1 []*github.R }{result1, result2, result3} } -func (fake *ReleaseService) Invocations() map[string][][]interface{} { +func (fake *ReleaseService) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.listReleasesMutex.RLock() defer fake.listReleasesMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *ReleaseService) recordInvocation(key string, args []interface{}) { +func (fake *ReleaseService) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/revision_resolver.go b/pkg/notes/internal/fakes/revision_resolver.go index 68269f21a..5d0e54f9b 100644 --- a/pkg/notes/internal/fakes/revision_resolver.go +++ b/pkg/notes/internal/fakes/revision_resolver.go @@ -21,7 +21,7 @@ type RevisionResolver struct { result1 *plumbing.Hash result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -33,7 +33,7 @@ func (fake *RevisionResolver) ResolveRevision(arg1 plumbing.Revision) (*plumbing }{arg1}) stub := fake.ResolveRevisionStub fakeReturns := fake.resolveRevisionReturns - fake.recordInvocation("ResolveRevision", []interface{}{arg1}) + fake.recordInvocation("ResolveRevision", []any{arg1}) fake.resolveRevisionMutex.Unlock() if stub != nil { return stub(arg1) @@ -89,26 +89,26 @@ func (fake *RevisionResolver) ResolveRevisionReturnsOnCall(i int, result1 *plumb }{result1, result2} } -func (fake *RevisionResolver) Invocations() map[string][][]interface{} { +func (fake *RevisionResolver) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.resolveRevisionMutex.RLock() defer fake.resolveRevisionMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *RevisionResolver) recordInvocation(key string, args []interface{}) { +func (fake *RevisionResolver) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/notes/internal/fakes/trainstat_client.go b/pkg/notes/internal/fakes/trainstat_client.go index 148f224a6..a2b72fe4a 100644 --- a/pkg/notes/internal/fakes/trainstat_client.go +++ b/pkg/notes/internal/fakes/trainstat_client.go @@ -22,7 +22,7 @@ type TrainstatClient struct { result1 []string result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -37,7 +37,7 @@ func (fake *TrainstatClient) FetchTrainstatNotes(ctx context.Context, arg1 strin }{ctx, arg1, arg2, arg3}) stub := fake.FetchStub fakeReturns := fake.fetchReturns - fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("Get", []any{arg1, arg2, arg3}) fake.fetchMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) @@ -83,24 +83,24 @@ func (fake *TrainstatClient) GetArgsForCall(i int) (string, string, string) { return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } -func (fake *TrainstatClient) Invocations() map[string][][]interface{} { +func (fake *TrainstatClient) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *TrainstatClient) recordInvocation(key string, args []interface{}) { +func (fake *TrainstatClient) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/example_product_service_test.go b/pkg/planitest/example_product_service_test.go index 8a6115901..9a97dc60e 100644 --- a/pkg/planitest/example_product_service_test.go +++ b/pkg/planitest/example_product_service_test.go @@ -37,7 +37,7 @@ product-properties: {} panic(err) } - manifest, err := product.RenderManifest(map[string]interface{}{ + manifest, err := product.RenderManifest(map[string]any{ ".properties.required": "foo", }) if err != nil { diff --git a/pkg/planitest/internal/config.go b/pkg/planitest/internal/config.go index 3579eec8f..7e5b40463 100644 --- a/pkg/planitest/internal/config.go +++ b/pkg/planitest/internal/config.go @@ -23,11 +23,11 @@ import ( // To work around this, we now have our own copy of ProductConfiguration without omit-empty on product-properties type ProductConfiguration struct { ProductName string `yaml:"product-name,omitempty"` - ProductProperties map[string]interface{} `yaml:"product-properties"` // remove omitempty - NetworkProperties map[string]interface{} `yaml:"network-properties,omitempty"` + ProductProperties map[string]any `yaml:"product-properties"` // remove omitempty + NetworkProperties map[string]any `yaml:"network-properties,omitempty"` ResourceConfigProperties map[string]config.ResourceConfig `yaml:"resource-config,omitempty"` ErrandConfigs map[string]config.ErrandConfig `yaml:"errand-config,omitempty"` - SyslogProperties map[string]interface{} `yaml:"syslog-properties,omitempty"` + SyslogProperties map[string]any `yaml:"syslog-properties,omitempty"` } // Force our "fork" of ProductConfiguration to have the same fields as the version in om/config @@ -35,7 +35,7 @@ var _ = config.ProductConfiguration(ProductConfiguration{}) // MergeAdditionalProductProperties takes product properties from the provided reader and merges them with data from the // additionalProperties parameter. It also does some validation to ensure required fields are set. -func MergeAdditionalProductProperties(configFile io.Reader, additionalProperties map[string]interface{}) (io.Reader, error) { +func MergeAdditionalProductProperties(configFile io.Reader, additionalProperties map[string]any) (io.Reader, error) { yamlInput, err := io.ReadAll(configFile) if err != nil { return nil, err @@ -67,14 +67,14 @@ func MergeAdditionalProductProperties(configFile io.Reader, additionalProperties return modifiedConfigFile, nil } -func mergeProperties(minimalProperties, additionalProperties map[string]interface{}) map[string]interface{} { - combinedProperties := make(map[string]interface{}, len(minimalProperties)+len(additionalProperties)) +func mergeProperties(minimalProperties, additionalProperties map[string]any) map[string]any { + combinedProperties := make(map[string]any, len(minimalProperties)+len(additionalProperties)) for k, v := range minimalProperties { combinedProperties[k] = v } for k, v := range additionalProperties { - combinedProperties[k] = map[string]interface{}{ + combinedProperties[k] = map[string]any{ "value": v, } } diff --git a/pkg/planitest/internal/fakes/command_runner.go b/pkg/planitest/internal/fakes/command_runner.go index e64ca7ab1..15f707195 100644 --- a/pkg/planitest/internal/fakes/command_runner.go +++ b/pkg/planitest/internal/fakes/command_runner.go @@ -24,7 +24,7 @@ type CommandRunner struct { result2 string result3 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -35,7 +35,7 @@ func (fake *CommandRunner) Run(arg1 string, arg2 ...string) (string, string, err arg1 string arg2 []string }{arg1, arg2}) - fake.recordInvocation("Run", []interface{}{arg1, arg2}) + fake.recordInvocation("Run", []any{arg1, arg2}) fake.runMutex.Unlock() if fake.RunStub != nil { return fake.RunStub(arg1, arg2...) @@ -95,26 +95,26 @@ func (fake *CommandRunner) RunReturnsOnCall(i int, result1 string, result2 strin }{result1, result2, result3} } -func (fake *CommandRunner) Invocations() map[string][][]interface{} { +func (fake *CommandRunner) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.runMutex.RLock() defer fake.runMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *CommandRunner) recordInvocation(key string, args []interface{}) { +func (fake *CommandRunner) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/internal/fakes/file_io.go b/pkg/planitest/internal/fakes/file_io.go index 990469f03..8280f8dc5 100644 --- a/pkg/planitest/internal/fakes/file_io.go +++ b/pkg/planitest/internal/fakes/file_io.go @@ -34,7 +34,7 @@ type FileIO struct { result1 *os.File result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -44,7 +44,7 @@ func (fake *FileIO) Remove(arg1 string) error { fake.removeArgsForCall = append(fake.removeArgsForCall, struct { arg1 string }{arg1}) - fake.recordInvocation("Remove", []interface{}{arg1}) + fake.recordInvocation("Remove", []any{arg1}) fake.removeMutex.Unlock() if fake.RemoveStub != nil { return fake.RemoveStub(arg1) @@ -105,7 +105,7 @@ func (fake *FileIO) TempFile(arg1 string, arg2 string) (*os.File, error) { arg1 string arg2 string }{arg1, arg2}) - fake.recordInvocation("TempFile", []interface{}{arg1, arg2}) + fake.recordInvocation("TempFile", []any{arg1, arg2}) fake.tempFileMutex.Unlock() if fake.TempFileStub != nil { return fake.TempFileStub(arg1, arg2) @@ -162,28 +162,28 @@ func (fake *FileIO) TempFileReturnsOnCall(i int, result1 *os.File, result2 error }{result1, result2} } -func (fake *FileIO) Invocations() map[string][][]interface{} { +func (fake *FileIO) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.removeMutex.RLock() defer fake.removeMutex.RUnlock() fake.tempFileMutex.RLock() defer fake.tempFileMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *FileIO) recordInvocation(key string, args []interface{}) { +func (fake *FileIO) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/internal/fakes/om_runner.go b/pkg/planitest/internal/fakes/om_runner.go index b590534f0..a056d9872 100644 --- a/pkg/planitest/internal/fakes/om_runner.go +++ b/pkg/planitest/internal/fakes/om_runner.go @@ -21,17 +21,17 @@ type OMRunner struct { result1 internal.StagedProduct result2 error } - GetManifestStub func(string) (map[string]interface{}, error) + GetManifestStub func(string) (map[string]any, error) getManifestMutex sync.RWMutex getManifestArgsForCall []struct { arg1 string } getManifestReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } getManifestReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } ResetAndConfigureStub func(string, string, string) error @@ -47,7 +47,7 @@ type OMRunner struct { resetAndConfigureReturnsOnCall map[int]struct { result1 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -57,7 +57,7 @@ func (fake *OMRunner) FindStagedProduct(arg1 string) (internal.StagedProduct, er fake.findStagedProductArgsForCall = append(fake.findStagedProductArgsForCall, struct { arg1 string }{arg1}) - fake.recordInvocation("FindStagedProduct", []interface{}{arg1}) + fake.recordInvocation("FindStagedProduct", []any{arg1}) fake.findStagedProductMutex.Unlock() if fake.FindStagedProductStub != nil { return fake.FindStagedProductStub(arg1) @@ -114,13 +114,13 @@ func (fake *OMRunner) FindStagedProductReturnsOnCall(i int, result1 internal.Sta }{result1, result2} } -func (fake *OMRunner) GetManifest(arg1 string) (map[string]interface{}, error) { +func (fake *OMRunner) GetManifest(arg1 string) (map[string]any, error) { fake.getManifestMutex.Lock() ret, specificReturn := fake.getManifestReturnsOnCall[len(fake.getManifestArgsForCall)] fake.getManifestArgsForCall = append(fake.getManifestArgsForCall, struct { arg1 string }{arg1}) - fake.recordInvocation("GetManifest", []interface{}{arg1}) + fake.recordInvocation("GetManifest", []any{arg1}) fake.getManifestMutex.Unlock() if fake.GetManifestStub != nil { return fake.GetManifestStub(arg1) @@ -138,7 +138,7 @@ func (fake *OMRunner) GetManifestCallCount() int { return len(fake.getManifestArgsForCall) } -func (fake *OMRunner) GetManifestCalls(stub func(string) (map[string]interface{}, error)) { +func (fake *OMRunner) GetManifestCalls(stub func(string) (map[string]any, error)) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = stub @@ -151,28 +151,28 @@ func (fake *OMRunner) GetManifestArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *OMRunner) GetManifestReturns(result1 map[string]interface{}, result2 error) { +func (fake *OMRunner) GetManifestReturns(result1 map[string]any, result2 error) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = nil fake.getManifestReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *OMRunner) GetManifestReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *OMRunner) GetManifestReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = nil if fake.getManifestReturnsOnCall == nil { fake.getManifestReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.getManifestReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } @@ -185,7 +185,7 @@ func (fake *OMRunner) ResetAndConfigure(arg1 string, arg2 string, arg3 string) e arg2 string arg3 string }{arg1, arg2, arg3}) - fake.recordInvocation("ResetAndConfigure", []interface{}{arg1, arg2, arg3}) + fake.recordInvocation("ResetAndConfigure", []any{arg1, arg2, arg3}) fake.resetAndConfigureMutex.Unlock() if fake.ResetAndConfigureStub != nil { return fake.ResetAndConfigureStub(arg1, arg2, arg3) @@ -239,7 +239,7 @@ func (fake *OMRunner) ResetAndConfigureReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *OMRunner) Invocations() map[string][][]interface{} { +func (fake *OMRunner) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.findStagedProductMutex.RLock() @@ -248,21 +248,21 @@ func (fake *OMRunner) Invocations() map[string][][]interface{} { defer fake.getManifestMutex.RUnlock() fake.resetAndConfigureMutex.RLock() defer fake.resetAndConfigureMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *OMRunner) recordInvocation(key string, args []interface{}) { +func (fake *OMRunner) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/internal/fakes/ops_manifest_runner.go b/pkg/planitest/internal/fakes/ops_manifest_runner.go index 491ca63ef..bbdb987cd 100644 --- a/pkg/planitest/internal/fakes/ops_manifest_runner.go +++ b/pkg/planitest/internal/fakes/ops_manifest_runner.go @@ -8,32 +8,32 @@ import ( ) type OpsManifestRunner struct { - GetManifestStub func(string, string) (map[string]interface{}, error) + GetManifestStub func(string, string) (map[string]any, error) getManifestMutex sync.RWMutex getManifestArgsForCall []struct { arg1 string arg2 string } getManifestReturns struct { - result1 map[string]interface{} + result1 map[string]any result2 error } getManifestReturnsOnCall map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } -func (fake *OpsManifestRunner) GetManifest(arg1 string, arg2 string) (map[string]interface{}, error) { +func (fake *OpsManifestRunner) GetManifest(arg1 string, arg2 string) (map[string]any, error) { fake.getManifestMutex.Lock() ret, specificReturn := fake.getManifestReturnsOnCall[len(fake.getManifestArgsForCall)] fake.getManifestArgsForCall = append(fake.getManifestArgsForCall, struct { arg1 string arg2 string }{arg1, arg2}) - fake.recordInvocation("GetManifest", []interface{}{arg1, arg2}) + fake.recordInvocation("GetManifest", []any{arg1, arg2}) fake.getManifestMutex.Unlock() if fake.GetManifestStub != nil { return fake.GetManifestStub(arg1, arg2) @@ -51,7 +51,7 @@ func (fake *OpsManifestRunner) GetManifestCallCount() int { return len(fake.getManifestArgsForCall) } -func (fake *OpsManifestRunner) GetManifestCalls(stub func(string, string) (map[string]interface{}, error)) { +func (fake *OpsManifestRunner) GetManifestCalls(stub func(string, string) (map[string]any, error)) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = stub @@ -64,52 +64,52 @@ func (fake *OpsManifestRunner) GetManifestArgsForCall(i int) (string, string) { return argsForCall.arg1, argsForCall.arg2 } -func (fake *OpsManifestRunner) GetManifestReturns(result1 map[string]interface{}, result2 error) { +func (fake *OpsManifestRunner) GetManifestReturns(result1 map[string]any, result2 error) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = nil fake.getManifestReturns = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *OpsManifestRunner) GetManifestReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { +func (fake *OpsManifestRunner) GetManifestReturnsOnCall(i int, result1 map[string]any, result2 error) { fake.getManifestMutex.Lock() defer fake.getManifestMutex.Unlock() fake.GetManifestStub = nil if fake.getManifestReturnsOnCall == nil { fake.getManifestReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} + result1 map[string]any result2 error }) } fake.getManifestReturnsOnCall[i] = struct { - result1 map[string]interface{} + result1 map[string]any result2 error }{result1, result2} } -func (fake *OpsManifestRunner) Invocations() map[string][][]interface{} { +func (fake *OpsManifestRunner) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.getManifestMutex.RLock() defer fake.getManifestMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *OpsManifestRunner) recordInvocation(key string, args []interface{}) { +func (fake *OpsManifestRunner) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/internal/fakes/render_service.go b/pkg/planitest/internal/fakes/render_service.go index 18cdce01c..2f92be93c 100644 --- a/pkg/planitest/internal/fakes/render_service.go +++ b/pkg/planitest/internal/fakes/render_service.go @@ -23,7 +23,7 @@ type RenderService struct { result1 string result2 error } - invocations map[string][][]interface{} + invocations map[string][][]any invocationsMutex sync.RWMutex } @@ -34,7 +34,7 @@ func (fake *RenderService) RenderManifest(arg1 io.Reader, arg2 io.Reader) (strin arg1 io.Reader arg2 io.Reader }{arg1, arg2}) - fake.recordInvocation("RenderManifest", []interface{}{arg1, arg2}) + fake.recordInvocation("RenderManifest", []any{arg1, arg2}) fake.renderManifestMutex.Unlock() if fake.RenderManifestStub != nil { return fake.RenderManifestStub(arg1, arg2) @@ -91,26 +91,26 @@ func (fake *RenderService) RenderManifestReturnsOnCall(i int, result1 string, re }{result1, result2} } -func (fake *RenderService) Invocations() map[string][][]interface{} { +func (fake *RenderService) Invocations() map[string][][]any { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.renderManifestMutex.RLock() defer fake.renderManifestMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} + copiedInvocations := map[string][][]any{} for key, value := range fake.invocations { copiedInvocations[key] = value } return copiedInvocations } -func (fake *RenderService) recordInvocation(key string, args []interface{}) { +func (fake *RenderService) recordInvocation(key string, args []any) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} + fake.invocations = map[string][][]any{} } if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} + fake.invocations[key] = [][]any{} } fake.invocations[key] = append(fake.invocations[key], args) } diff --git a/pkg/planitest/internal/internal.go b/pkg/planitest/internal/internal.go index 5877eae5d..9e8cdc67c 100644 --- a/pkg/planitest/internal/internal.go +++ b/pkg/planitest/internal/internal.go @@ -7,13 +7,13 @@ import ( //counterfeiter:generate ./fakes/om_runner.go --fake-name OMRunner . OMRunnerI type OMRunnerI interface { ResetAndConfigure(productName string, productVersion string, configJSON string) error - GetManifest(productGUID string) (map[string]interface{}, error) + GetManifest(productGUID string) (map[string]any, error) FindStagedProduct(productName string) (StagedProduct, error) } //counterfeiter:generate ./fakes/ops_manifest_runner.go --fake-name OpsManifestRunner . OpsManifestRunnerI type OpsManifestRunnerI interface { - GetManifest(productProperties, metadataFilePath string) (map[string]interface{}, error) + GetManifest(productProperties, metadataFilePath string) (map[string]any, error) } //counterfeiter:generate ./fakes/file_io.go --fake-name FileIO . FileIO diff --git a/pkg/planitest/internal/om_runner.go b/pkg/planitest/internal/om_runner.go index 5c8f24b18..40fc80249 100644 --- a/pkg/planitest/internal/om_runner.go +++ b/pkg/planitest/internal/om_runner.go @@ -18,7 +18,7 @@ type StagedProduct struct { } type stagedManifestResponse struct { - Manifest map[string]interface{} + Manifest map[string]any Errors OMError `json:"errors"` } @@ -122,7 +122,7 @@ func (o OMRunner) ResetAndConfigure(productName string, productVersion string, c return nil } -func (o OMRunner) GetManifest(productGUID string) (map[string]interface{}, error) { +func (o OMRunner) GetManifest(productGUID string) (map[string]any, error) { response, errOutput, err := o.cmdRunner.Run( "om", "--skip-ssl-validation", diff --git a/pkg/planitest/internal/om_runner_test.go b/pkg/planitest/internal/om_runner_test.go index ab7fc26d3..a12bde77c 100644 --- a/pkg/planitest/internal/om_runner_test.go +++ b/pkg/planitest/internal/om_runner_test.go @@ -258,10 +258,10 @@ network-properties: "--path", "/api/v0/staged/products/some-guid/manifest", })) - Expect(manifest).To(Equal(map[string]interface{}{ + Expect(manifest).To(Equal(map[string]any{ "name": "cf-some-guid", - "releases": []interface{}{ - map[string]interface{}{ + "releases": []any{ + map[string]any{ "name": "some-release", "version": "1.2.3", }, diff --git a/pkg/planitest/internal/om_service_test.go b/pkg/planitest/internal/om_service_test.go index 4d76564bb..9dad3bd06 100644 --- a/pkg/planitest/internal/om_service_test.go +++ b/pkg/planitest/internal/om_service_test.go @@ -64,7 +64,7 @@ product_version: 1.2.3 Type: "some-type", ProductVersion: "some-version", }, nil) - omRunner.GetManifestReturns(map[string]interface{}{ + omRunner.GetManifestReturns(map[string]any{ "some-key": "some-value", }, nil) }) diff --git a/pkg/planitest/internal/ops_manifest_runner.go b/pkg/planitest/internal/ops_manifest_runner.go index 38dd85773..bca0452d4 100644 --- a/pkg/planitest/internal/ops_manifest_runner.go +++ b/pkg/planitest/internal/ops_manifest_runner.go @@ -21,7 +21,7 @@ func NewOpsManifestRunner(cmdRunner CommandRunner, fileIO FileIO, additionalArgs } } -func (o OpsManifestRunner) GetManifest(productProperties, metadataFilePath string) (map[string]interface{}, error) { +func (o OpsManifestRunner) GetManifest(productProperties, metadataFilePath string) (map[string]any, error) { configFile, err := o.FileIO.TempFile("", "") configFileYML := fmt.Sprintf("%s.yml", configFile.Name()) _ = os.Rename(configFile.Name(), configFileYML) @@ -43,7 +43,7 @@ func (o OpsManifestRunner) GetManifest(productProperties, metadataFilePath strin return nil, fmt.Errorf("Unable to retrieve manifest: %s: %s", err, errOutput) } - var manifest map[string]interface{} + var manifest map[string]any err = yaml.Unmarshal([]byte(response), &manifest) if err != nil { return nil, fmt.Errorf("Unable to unmarshal yaml: %s", err) diff --git a/pkg/planitest/internal/ops_manifest_runner_test.go b/pkg/planitest/internal/ops_manifest_runner_test.go index a67644156..8550d0020 100644 --- a/pkg/planitest/internal/ops_manifest_runner_test.go +++ b/pkg/planitest/internal/ops_manifest_runner_test.go @@ -50,10 +50,10 @@ var _ = Describe("OMRunner", func() { Expect(args[2]).To(ContainSubstring("--metadata-path")) Expect(args[3]).To(ContainSubstring("some/metadata/path")) - Expect(manifest).To(Equal(map[string]interface{}{ + Expect(manifest).To(Equal(map[string]any{ "name": "cf-some-guid", - "releases": []interface{}{ - map[interface{}]interface{}{ + "releases": []any{ + map[any]any{ "name": "some-release", "version": "1.2.3", }, @@ -94,10 +94,10 @@ var _ = Describe("OMRunner", func() { Expect(args[6]).To(Equal("--tas-config-file")) Expect(args[7]).To(Equal(tasConfigPath)) - Expect(manifest).To(Equal(map[string]interface{}{ + Expect(manifest).To(Equal(map[string]any{ "name": "cf-some-guid", - "releases": []interface{}{ - map[interface{}]interface{}{ + "releases": []any{ + map[any]any{ "name": "some-release", "version": "1.2.3", }, diff --git a/pkg/planitest/internal/ops_manifest_service_test.go b/pkg/planitest/internal/ops_manifest_service_test.go index d4ae278d0..6b26af59a 100644 --- a/pkg/planitest/internal/ops_manifest_service_test.go +++ b/pkg/planitest/internal/ops_manifest_service_test.go @@ -29,7 +29,7 @@ var _ = Describe("OpsManifest Service", func() { Describe("RenderManifest", func() { It("calls ops-manifest to retrieve the manifest", func() { - opsManifestRunner.GetManifestReturns(map[string]interface{}{ + opsManifestRunner.GetManifestReturns(map[string]any{ "some-key": "some-value", }, nil) diff --git a/pkg/planitest/manifest.go b/pkg/planitest/manifest.go index f787f2a4a..36fc9c9a1 100644 --- a/pkg/planitest/manifest.go +++ b/pkg/planitest/manifest.go @@ -24,16 +24,16 @@ func (m Manifest) FindInstanceGroupJob(instanceGroup, job string) (Manifest, err return Manifest(content), nil } -func (m Manifest) Property(path string) (interface{}, error) { +func (m Manifest) Property(path string) (any, error) { return m.interpolate(fmt.Sprintf("/properties/%s", path)) } -func (m Manifest) Path(path string) (interface{}, error) { +func (m Manifest) Path(path string) (any, error) { return m.interpolate(path) } -func (m Manifest) interpolate(path string) (interface{}, error) { - var content interface{} +func (m Manifest) interpolate(path string) (any, error) { + var content any err := yaml.Unmarshal([]byte(m), &content) if err != nil { return "", fmt.Errorf("failed to parse manifest: %s", err) diff --git a/pkg/planitest/product_service.go b/pkg/planitest/product_service.go index ff30d18ad..e972851ee 100644 --- a/pkg/planitest/product_service.go +++ b/pkg/planitest/product_service.go @@ -67,7 +67,7 @@ func opsManifestAdditionalArgs() []string { return args } -func (p *ProductService) RenderManifest(additionalProperties map[string]interface{}) (Manifest, error) { +func (p *ProductService) RenderManifest(additionalProperties map[string]any) (Manifest, error) { _, err := p.config.ConfigFile.Seek(0, 0) if err != nil { return "", err diff --git a/pkg/proofing/install_time_verifier.go b/pkg/proofing/install_time_verifier.go index 18c67cfff..62e924396 100644 --- a/pkg/proofing/install_time_verifier.go +++ b/pkg/proofing/install_time_verifier.go @@ -1,7 +1,7 @@ package proofing type InstallTimeVerifier struct { - Ignorable bool `yaml:"ignorable,omitempty"` - Name string `yaml:"name"` - Properties interface{} `yaml:"properties"` // TODO: schema? + Ignorable bool `yaml:"ignorable,omitempty"` + Name string `yaml:"name"` + Properties any `yaml:"properties"` // TODO: schema? } diff --git a/pkg/proofing/job_type.go b/pkg/proofing/job_type.go index b18ac0893..3a640a247 100644 --- a/pkg/proofing/job_type.go +++ b/pkg/proofing/job_type.go @@ -5,8 +5,8 @@ type JobType struct { ResourceLabel string `yaml:"resource_label"` Description string `yaml:"description,omitempty"` - Manifest string `yaml:"manifest"` - MaxInFlight interface{} `yaml:"max_in_flight"` + Manifest string `yaml:"manifest"` + MaxInFlight any `yaml:"max_in_flight"` Canaries int `yaml:"canaries"` Serial bool `yaml:"serial,omitempty"` diff --git a/pkg/proofing/resource_definition.go b/pkg/proofing/resource_definition.go index 7c5f82db7..69ddc3e62 100644 --- a/pkg/proofing/resource_definition.go +++ b/pkg/proofing/resource_definition.go @@ -1,10 +1,10 @@ package proofing type ResourceDefinition struct { - Name string `yaml:"name"` - Default int `yaml:"default"` - Configurable bool `yaml:"configurable"` - Constraints interface{} `yaml:"constraints,omitempty"` // TODO: schema? + Name string `yaml:"name"` + Default int `yaml:"default"` + Configurable bool `yaml:"configurable"` + Constraints any `yaml:"constraints,omitempty"` // TODO: schema? // TODO: validations: https://github.com/pivotal-cf/installation/blob/039a2ef3f751ef5915c425da8150a29af4b764dd/web/app/models/persistence/metadata/resource_definition.rb#L9 } diff --git a/pkg/proofing/simple_property_blueprint.go b/pkg/proofing/simple_property_blueprint.go index b57f4f25c..167a7700a 100644 --- a/pkg/proofing/simple_property_blueprint.go +++ b/pkg/proofing/simple_property_blueprint.go @@ -3,8 +3,8 @@ package proofing type SimplePropertyBlueprint struct { Name string `yaml:"name"` Type string `yaml:"type"` - Default interface{} `yaml:"default"` // TODO: schema? - Constraints interface{} `yaml:"constraints"` // TODO: schema? + Default any `yaml:"default"` // TODO: schema? + Constraints any `yaml:"constraints"` // TODO: schema? Options []PropertyBlueprintOption `yaml:"options"` // TODO: schema? Configurable bool `yaml:"configurable"` Optional bool `yaml:"optional"` diff --git a/pkg/proofing/upgrade/breaking_changes_test.go b/pkg/proofing/upgrade/breaking_changes_test.go index 65e6cb11d..a04dd261a 100644 --- a/pkg/proofing/upgrade/breaking_changes_test.go +++ b/pkg/proofing/upgrade/breaking_changes_test.go @@ -194,7 +194,7 @@ func loadMetadataProperties(t *testing.T) (initial, patch proofing.ProductTempla return } -func readYAMLFile(t *testing.T, filePath string, data interface{}) { +func readYAMLFile(t *testing.T, filePath string, data any) { iBuf, err := os.ReadFile(filePath) if err != nil { t.Fatal(err) diff --git a/pkg/proofing/validation_error.go b/pkg/proofing/validation_error.go index 148a1df71..1cd07a075 100644 --- a/pkg/proofing/validation_error.go +++ b/pkg/proofing/validation_error.go @@ -7,11 +7,11 @@ import ( ) type ValidationError struct { - Kind interface{} + Kind any Message string } -func NewValidationError(kind interface{}, message string) ValidationError { +func NewValidationError(kind any, message string) ValidationError { return ValidationError{ Kind: kind, Message: message, @@ -23,7 +23,7 @@ func (ve ValidationError) Error() string { return fmt.Sprintf("%s %s", strings.ToLower(t.Name()), ve.Message) } -func ValidatePresence(err error, v interface{}, field string) error { +func ValidatePresence(err error, v any, field string) error { value := reflect.ValueOf(v).FieldByName(field) if value.Len() == 0 { validationError := NewValidationError(v, fmt.Sprintf("%s must be present", strings.ToLower(field))) diff --git a/pkg/proofing/variable.go b/pkg/proofing/variable.go index 0ae950e69..92dc21aee 100644 --- a/pkg/proofing/variable.go +++ b/pkg/proofing/variable.go @@ -1,7 +1,7 @@ package proofing type Variable struct { - Name string `yaml:"name"` - Options interface{} `yaml:"options,omitempty"` // TODO: schema? - Type string `yaml:"type"` + Name string `yaml:"name"` + Options any `yaml:"options,omitempty"` // TODO: schema? + Type string `yaml:"type"` } diff --git a/pkg/proofing/verifier_blueprint.go b/pkg/proofing/verifier_blueprint.go index bb01812ba..6979614ea 100644 --- a/pkg/proofing/verifier_blueprint.go +++ b/pkg/proofing/verifier_blueprint.go @@ -1,6 +1,6 @@ package proofing type VerifierBlueprint struct { - Name string `yaml:"name"` - Properties interface{} `yaml:"properties"` // TODO: schema? + Name string `yaml:"name"` + Properties any `yaml:"properties"` // TODO: schema? } diff --git a/pkg/tile/release.go b/pkg/tile/release.go deleted file mode 100644 index 3cddb6f33..000000000 --- a/pkg/tile/release.go +++ /dev/null @@ -1,72 +0,0 @@ -package tile - -import ( - "archive/zip" - "fmt" - "io" - "io/fs" - "os" - "path" - - "golang.org/x/exp/slices" - "gopkg.in/yaml.v2" - - "github.com/pivotal-cf/kiln/pkg/proofing" -) - -func ReadReleaseFromFile(tilePath, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { - f, err := os.Open(tilePath) - if err != nil { - return proofing.Release{}, err - } - defer closeAndIgnoreError(f) - fi, err := f.Stat() - if err != nil { - return proofing.Release{}, err - } - return ReadReleaseFromZip(f, fi.Size(), releaseName, releaseVersion, releaseTarball) -} - -func ReadReleaseFromZip(ra io.ReaderAt, zipFileSize int64, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { - zr, err := zip.NewReader(ra, zipFileSize) - if err != nil { - return proofing.Release{}, fmt.Errorf("failed to do open metadata zip reader: %w", err) - } - return ReadReleaseFromFS(zr, releaseName, releaseVersion, releaseTarball) -} - -func ReadReleaseFromFS(dir fs.FS, releaseName, releaseVersion string, releaseTarball io.Writer) (proofing.Release, error) { - metadataBuf, err := ReadMetadataFromFS(dir) - if err != nil { - return proofing.Release{}, err - } - - var metadata struct { - Releases []proofing.Release `yaml:"releases"` - } - err = yaml.Unmarshal(metadataBuf, &metadata) - if err != nil { - return proofing.Release{}, err - } - - releaseIndex := slices.IndexFunc(metadata.Releases, func(release proofing.Release) bool { - return release.Name == releaseName && release.Version == releaseVersion - }) - if releaseIndex == -1 { - return proofing.Release{}, fmt.Errorf("release not found with %s/%s", releaseName, releaseVersion) - } - release := metadata.Releases[releaseIndex] - - f, err := dir.Open(path.Join("releases", release.File)) - if err != nil { - return proofing.Release{}, err - } - defer closeAndIgnoreError(f) - - _, err = io.Copy(releaseTarball, f) - if err != nil { - return proofing.Release{}, fmt.Errorf("failed to copy release tarball: %w", err) - } - - return release, nil -} diff --git a/pkg/tile/releases_test.go b/pkg/tile/releases_test.go deleted file mode 100644 index ee66975a6..000000000 --- a/pkg/tile/releases_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package tile_test - -import ( - "bytes" - "io" - "testing" - - "github.com/pivotal-cf/kiln/pkg/proofing" - - . "github.com/onsi/gomega" - - "github.com/pivotal-cf/kiln/pkg/tile" -) - -func TestReadReleaseFromFile(t *testing.T) { - please := NewWithT(t) - - buf := bytes.NewBuffer(nil) - releaseMetadata, err := tile.ReadReleaseFromFile("testdata/tile-0.1.2.pivotal", "hello-release", "v0.1.4", buf) - please.Expect(err).NotTo(HaveOccurred()) - - please.Expect(releaseMetadata).To(Equal(proofing.Release{ - File: "hello-release-v0.1.4-ubuntu-xenial-621.256.tgz", - Name: "hello-release", - SHA1: "c471ac6371eb8fc24508b14d9a49a44f9a5ef98c", - Version: "v0.1.4", - })) - - _, err = io.ReadAll(buf) - please.Expect(err).NotTo(HaveOccurred()) -}