Skip to content

Commit

Permalink
chore: address PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Apr 15, 2024
1 parent 1eeb39c commit 33a6df6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions spdx/v2/v2_2/json/empty_values_test.go
Expand Up @@ -12,7 +12,7 @@ func Test_omitsAppropriateProperties(t *testing.T) {
tests := []struct {
name string
pkg spdx.Package
validate func(t *testing.T, got string)
validate func(t *testing.T, got map[string]interface{})
}{
{
name: "include packageVerificationCode exclusions",
Expand All @@ -21,7 +21,7 @@ func Test_omitsAppropriateProperties(t *testing.T) {
ExcludedFiles: []string{},
},
},
validate: func(t *testing.T, got string) {
validate: func(t *testing.T, got map[string]interface{}) {
require.Contains(t, got, "packageVerificationCode")
},
},
Expand All @@ -32,7 +32,7 @@ func Test_omitsAppropriateProperties(t *testing.T) {
Value: "1234",
},
},
validate: func(t *testing.T, got string) {
validate: func(t *testing.T, got map[string]interface{}) {
require.Contains(t, got, "packageVerificationCode")
},
},
Expand All @@ -41,7 +41,7 @@ func Test_omitsAppropriateProperties(t *testing.T) {
pkg: spdx.Package{
PackageVerificationCode: common.PackageVerificationCode{},
},
validate: func(t *testing.T, got string) {
validate: func(t *testing.T, got map[string]interface{}) {
require.NotContains(t, got, "packageVerificationCode")
},
},
Expand All @@ -51,7 +51,10 @@ func Test_omitsAppropriateProperties(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
got, err := json.Marshal(test.pkg)
require.NoError(t, err)
test.validate(t, string(got))
var unmarshalled map[string]interface{}
err = json.Unmarshal(got, &unmarshalled)
require.NoError(t, err)
test.validate(t, unmarshalled)
})
}
}
6 changes: 4 additions & 2 deletions spdx/v2/v2_2/package.go
Expand Up @@ -132,8 +132,10 @@ func (p Package) MarshalJSON() ([]byte, error) {
return nil, err
}

// remove empty packageVerificationCode entries -- required by 2.2 JSON schema but
// omitempty has no effect since it is a non-comparable struct and not a pointer
// remove empty packageVerificationCode entries -- required by SPDX 2.2 but
// omitempty has no effect since it is a non-comparable struct and not a pointer, so we
// manually check to determine if there is a valid value to output and omit the field if not
// see: https://spdx.github.io/spdx-spec/v2.2.2/package-information/#79-package-verification-code-field
if p.PackageVerificationCode.Value == "" && p.PackageVerificationCode.ExcludedFiles == nil {
var values map[string]interface{}
err = json.Unmarshal(data, &values)
Expand Down

0 comments on commit 33a6df6

Please sign in to comment.