Skip to content

Commit

Permalink
Fix Vet Errors (#2153)
Browse files Browse the repository at this point in the history
* Fix lint errors for unkeyed fields in composite literals

Signed-off-by: Tanmay Chaudhry <[email protected]>

* resolve lint errors on tags

Signed-off-by: Tanmay Chaudhry <[email protected]>

* Updated golden file to account for bad struct tag fix

Signed-off-by: Tanmay Chaudhry <[email protected]>

* Vet Fix: Rename example tests to use suffixes.

Signed-off-by: Tanmay Chaudhry <[email protected]>

* Replace ExtendedBundle{} initialization with a NewBundle constructor

Signed-off-by: Tanmay Chaudhry <[email protected]>
  • Loading branch information
tchaudhry91 authored Jun 16, 2022
1 parent d50f5da commit 0c3d0b6
Show file tree
Hide file tree
Showing 46 changed files with 173 additions and 168 deletions.
8 changes: 4 additions & 4 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,25 @@ func TestStoreManifest(t *testing.T) {
}{
{
name: "embedded manifest",
bundle: cnab.ExtendedBundle{bundle.Bundle{
bundle: cnab.NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
"sh.porter": map[string]interface{}{
"manifest": "bmFtZTogSEVMTE9fQ1VTVE9NCnZlcnNpb246IDAuMS4wCmRlc2NyaXB0aW9uOiAiQSBidW5kbGUgd2l0aCBhIGN1c3RvbSBhY3Rpb24iCnRhZzogZ2V0cG9ydGVyL3BvcnRlci1oZWxsbzp2MC4xLjAKaW52b2NhdGlvbkltYWdlOiBnZXRwb3J0ZXIvcG9ydGVyLWhlbGxvLWluc3RhbGxlcjowLjEuMAoKY3JlZGVudGlhbHM6CiAgLSBuYW1lOiBteS1maXJzdC1jcmVkCiAgICBlbnY6IE1ZX0ZJUlNUX0NSRUQKICAtIG5hbWU6IG15LXNlY29uZC1jcmVkCiAgICBkZXNjcmlwdGlvbjogIk15IHNlY29uZCBjcmVkIgogICAgcGF0aDogL3BhdGgvdG8vbXktc2Vjb25kLWNyZWQKCmltYWdlczogCiAgIHNvbWV0aGluZzoKICAgICAgZGVzY3JpcHRpb246IC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xkIDIuMCIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIFdvcmxkIDIuMAoKem9tYmllczoKICAtIGV4ZWM6CiAgICAgIGRlc2NyaXB0aW9uOiAiVHJpZ2dlciB6b21iaWUgYXBvY2FseXBzZSIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIG9oIG5vZXMgbXkgYnJhaW5zCgp1bmluc3RhbGw6CiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogIlVuaW5zdGFsbCBIZWxsbyBXb3JsZCIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIEdvb2RieWUgV29ybGQK",
},
},
}},
}),
tag: kahn1dot01,
shouldCacheManifest: true,
},
{
name: "porter stamp, no manifest",
bundle: cnab.ExtendedBundle{bundle.Bundle{
bundle: cnab.NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
"sh.porter": map[string]interface{}{
"manifestDigest": "abc123",
},
},
}},
}),
tag: kahn1dot01,
shouldCacheManifest: false,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cnab/cnab-to-oci/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Registry) PullBundle(ref cnab.OCIReference, insecureRegistry bool) (cna
bundleRef := cnab.BundleReference{
Reference: ref,
Digest: digest,
Definition: cnab.ExtendedBundle{*bun},
Definition: cnab.NewBundle(*bun),
RelocationMap: reloMap,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cnab/config-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func (c *ManifestConverter) ToBundle(ctx context.Context) (cnab.ExtendedBundle,
return cnab.ExtendedBundle{}, span.Error(err)
}

b := cnab.ExtendedBundle{bundle.Bundle{
b := cnab.NewBundle(bundle.Bundle{
SchemaVersion: SchemaVersion,
Name: c.Manifest.Name,
Description: c.Manifest.Description,
Version: c.Manifest.Version,
Maintainers: c.generateBundleMaintainers(),
Custom: make(map[string]interface{}, 1),
}}
})
image := bundle.InvocationImage{
BaseImage: bundle.BaseImage{
Image: c.Manifest.Image,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cnab/config-adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func TestNewManifestConverter_generateOutputWiringParameter(t *testing.T) {
outputDef := definition.Schema{
Type: "string",
}
b := cnab.ExtendedBundle{bundle.Bundle{
b := cnab.NewBundle(bundle.Bundle{
Outputs: map[string]bundle.Output{
"msg": {
Definition: "stringDef",
Expand All @@ -671,7 +671,7 @@ func TestNewManifestConverter_generateOutputWiringParameter(t *testing.T) {
Definitions: map[string]*definition.Schema{
"stringDef": &outputDef,
},
}}
})

t.Run("generate parameter", func(t *testing.T) {
t.Parallel()
Expand Down
8 changes: 4 additions & 4 deletions pkg/cnab/config-adapter/stamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestConfig_GenerateStamp(t *testing.T) {
func TestConfig_LoadStamp(t *testing.T) {
t.Parallel()

bun := cnab.ExtendedBundle{bundle.Bundle{
bun := cnab.NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
config.CustomPorterKey: map[string]interface{}{
"manifestDigest": "somedigest",
Expand All @@ -60,7 +60,7 @@ func TestConfig_LoadStamp(t *testing.T) {
},
},
},
}}
})

stamp, err := LoadStamp(bun)
require.NoError(t, err)
Expand All @@ -72,13 +72,13 @@ func TestConfig_LoadStamp(t *testing.T) {
func TestConfig_LoadStamp_Invalid(t *testing.T) {
t.Parallel()

bun := cnab.ExtendedBundle{bundle.Bundle{
bun := cnab.NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
config.CustomPorterKey: []string{
"somedigest",
},
},
}}
})

stamp, err := LoadStamp(bun)
require.Error(t, err)
Expand Down
18 changes: 9 additions & 9 deletions pkg/cnab/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestReadDependencyProperties(t *testing.T) {
b, err := bundle.Unmarshal(data)
require.NoError(t, err, "could not unmarshal the bundle")

bun := ExtendedBundle{*b}
bun := NewBundle(*b)
assert.True(t, bun.HasDependencies())

deps, err := bun.ReadDependencies()
Expand All @@ -44,7 +44,7 @@ func TestDependencies_ListBySequence(t *testing.T) {

sequenceMock := []string{"nginx", "storage", "mysql"}

bun := ExtendedBundle{bundle.Bundle{
bun := NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
DependenciesExtensionKey: Dependencies{
Sequence: sequenceMock,
Expand All @@ -68,7 +68,7 @@ func TestDependencies_ListBySequence(t *testing.T) {
},
},
},
}}
})

rawDeps, err := bun.ReadDependencies()
orderedDeps := rawDeps.ListBySequence()
Expand All @@ -92,9 +92,9 @@ func TestSupportsDependencies(t *testing.T) {
t.Parallel()

t.Run("supported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{DependenciesExtensionKey},
}}
})

assert.True(t, b.SupportsDependencies())
})
Expand All @@ -109,19 +109,19 @@ func TestHasDependencies(t *testing.T) {
t.Parallel()

t.Run("has dependencies", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{DependenciesExtensionKey},
Custom: map[string]interface{}{
DependenciesExtensionKey: struct{}{},
},
}}
})

assert.True(t, b.HasDependencies())
})
t.Run("no dependencies", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{DependenciesExtensionKey},
}}
})

assert.False(t, b.HasDependencies())
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/cnab/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func TestSupportsDocker(t *testing.T) {
t.Parallel()

t.Run("supported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{DockerExtensionKey},
}}
})

assert.True(t, b.SupportsDocker())
})
t.Run("unsupported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{}}
b := NewBundle(bundle.Bundle{})

assert.False(t, b.SupportsDocker())
})
Expand Down
7 changes: 6 additions & 1 deletion pkg/cnab/extended_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type ExtendedBundle struct {
bundle.Bundle
}

// NewBundle creates an ExtendedBundle from a given bundle.
func NewBundle(bundle bundle.Bundle) ExtendedBundle {
return ExtendedBundle{bundle}
}

// LoadBundle from the specified filepath.
func LoadBundle(c *portercontext.Context, bundleFile string) (ExtendedBundle, error) {
bunD, err := c.FileSystem.ReadFile(bundleFile)
Expand All @@ -29,7 +34,7 @@ func LoadBundle(c *portercontext.Context, bundleFile string) (ExtendedBundle, er
return ExtendedBundle{}, errors.Wrapf(err, "cannot load bundle from\n%s at %s", string(bunD), bundleFile)
}

return ExtendedBundle{*bun}, nil
return NewBundle(*bun), nil
}

// IsPorterBundle determines if the bundle was created by Porter.
Expand Down
16 changes: 8 additions & 8 deletions pkg/cnab/extended_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func TestExtendedBundle_IsPorterBundle(t *testing.T) {
t.Run("made by porter", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
Custom: map[string]interface{}{
"sh.porter": struct{}{},
},
}}
})

assert.True(t, b.IsPorterBundle())
})
Expand All @@ -35,7 +35,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) {
Type: "string",
ContentEncoding: "base64",
}
bun := ExtendedBundle{bundle.Bundle{
bun := NewBundle(bundle.Bundle{
RequiredExtensions: []string{
FileParameterExtensionKey,
},
Expand All @@ -52,7 +52,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) {
Definition: "file",
},
},
}}
})

assert.False(t, bun.IsFileType(stringDef), "strings should not be flagged as files")
assert.True(t, bun.IsFileType(fileDef), "strings+base64 with the file-parameters extension should be categorized as files")
Expand All @@ -70,7 +70,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) {
}

func TestExtendedBundle_IsInternalParameter(t *testing.T) {
bun := ExtendedBundle{bundle.Bundle{
bun := NewBundle(bundle.Bundle{
Definitions: definition.Definitions{
"foo": &definition.Schema{
Type: "string",
Expand All @@ -91,7 +91,7 @@ func TestExtendedBundle_IsInternalParameter(t *testing.T) {
Definition: "porter-debug",
},
},
}}
})

t.Run("empty bundle", func(t *testing.T) {
b := ExtendedBundle{}
Expand All @@ -117,7 +117,7 @@ func TestExtendedBundle_IsInternalParameter(t *testing.T) {

func TestExtendedBundle_IsSensitiveParameter(t *testing.T) {
sensitive := true
bun := ExtendedBundle{bundle.Bundle{
bun := NewBundle(bundle.Bundle{
Definitions: definition.Definitions{
"foo": &definition.Schema{
Type: "string",
Expand All @@ -139,7 +139,7 @@ func TestExtendedBundle_IsSensitiveParameter(t *testing.T) {
Definition: "porter-debug",
},
},
}}
})

t.Run("empty bundle", func(t *testing.T) {
b := ExtendedBundle{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cnab/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

func TestSupportsExtension(t *testing.T) {
t.Run("key present", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{RequiredExtensions: []string{"io.test.thing"}}}
b := NewBundle(bundle.Bundle{RequiredExtensions: []string{"io.test.thing"}})
assert.True(t, b.SupportsExtension("io.test.thing"))
})

t.Run("key missing", func(t *testing.T) {
// We need to match against the full key, not just shorthand
b := ExtendedBundle{bundle.Bundle{RequiredExtensions: []string{"thing"}}}
b := NewBundle(bundle.Bundle{RequiredExtensions: []string{"thing"}})
assert.False(t, b.SupportsExtension("io.test.thing"))
})
}
6 changes: 3 additions & 3 deletions pkg/cnab/file_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func TestSupportsFileParameters(t *testing.T) {
t.Parallel()

t.Run("supported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{FileParameterExtensionKey},
}}
})

assert.True(t, b.SupportsFileParameters())
})
t.Run("unsupported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{}}
b := NewBundle(bundle.Bundle{})

assert.False(t, b.SupportsFileParameters())
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cnab/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func ReadTestBundle(t *testing.T, path string) ExtendedBundle {
bun, err := bundle.Unmarshal(bunD)
require.NoError(t, err, "Unmarshal failed for bundle at %s", path)

return ExtendedBundle{*bun}
return NewBundle(*bun)
}
14 changes: 7 additions & 7 deletions pkg/cnab/parameter_sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestReadParameterSourcesProperties(t *testing.T) {

b, err := bundle.Unmarshal(data)
require.NoError(t, err, "could not unmarshal the bundle")
bun := ExtendedBundle{*b}
bun := NewBundle(*b)
assert.True(t, bun.HasParameterSources())

ps, err := bun.ReadParameterSources()
Expand Down Expand Up @@ -88,9 +88,9 @@ func TestSupportsParameterSources(t *testing.T) {
t.Parallel()

t.Run("supported", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{ParameterSourcesExtensionKey},
}}
})

assert.True(t, b.SupportsParameterSources())
})
Expand All @@ -105,19 +105,19 @@ func TestHasParameterSources(t *testing.T) {
t.Parallel()

t.Run("has parameter sources", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{ParameterSourcesExtensionKey},
Custom: map[string]interface{}{
ParameterSourcesExtensionKey: struct{}{},
},
}}
})

assert.True(t, b.HasParameterSources())
})
t.Run("no parameter sources", func(t *testing.T) {
b := ExtendedBundle{bundle.Bundle{
b := NewBundle(bundle.Bundle{
RequiredExtensions: []string{ParameterSourcesExtensionKey},
}}
})

assert.False(t, b.HasParameterSources())
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/cnab/provider/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (r *Runtime) CreateRun(ctx context.Context, args ActionArguments, b cnab.Ex
currentRun.BundleDigest = args.BundleReference.Digest.String()

var err error
extb := cnab.ExtendedBundle{b.Bundle}
extb := cnab.NewBundle(b.Bundle)
currentRun.Parameters.Parameters, err = r.sanitizer.CleanRawParameters(ctx, args.Params, extb, currentRun.ID)
if err != nil {
return storage.Run{}, span.Error(err)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (r *Runtime) SaveOperationResult(ctx context.Context, opResult driver.Opera

for outputName, outputValue := range opResult.Outputs {
output := result.NewOutput(outputName, []byte(outputValue))
output, err = r.sanitizer.CleanOutput(ctx, output, cnab.ExtendedBundle{run.Bundle})
output, err = r.sanitizer.CleanOutput(ctx, output, cnab.ExtendedBundle{Bundle: run.Bundle})
if err != nil {
bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error sanitizing sensitive %s output for %s run of installation %s\n%#v", output.Name, run.Action, installation, output))
}
Expand Down
Loading

0 comments on commit 0c3d0b6

Please sign in to comment.