-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(2.2 json): remove emtpy packageVerificationCode (#223)
Signed-off-by: Keith Zantow <[email protected]>
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package json | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/spdx/tools-golang/spdx/v2/common" | ||
spdx "github.com/spdx/tools-golang/spdx/v2/v2_2" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func Test_omitsAppropriateProperties(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
pkg spdx.Package | ||
validate func(t *testing.T, got map[string]interface{}) | ||
}{ | ||
{ | ||
name: "include packageVerificationCode exclusions", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{ | ||
ExcludedFiles: []string{}, | ||
}, | ||
}, | ||
validate: func(t *testing.T, got map[string]interface{}) { | ||
require.Contains(t, got, "packageVerificationCode") | ||
}, | ||
}, | ||
{ | ||
name: "include packageVerificationCode value", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{ | ||
Value: "1234", | ||
}, | ||
}, | ||
validate: func(t *testing.T, got map[string]interface{}) { | ||
require.Contains(t, got, "packageVerificationCode") | ||
}, | ||
}, | ||
{ | ||
name: "omit empty packageVerificationCode", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{}, | ||
}, | ||
validate: func(t *testing.T, got map[string]interface{}) { | ||
require.NotContains(t, got, "packageVerificationCode") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got, err := json.Marshal(test.pkg) | ||
require.NoError(t, err) | ||
var unmarshalled map[string]interface{} | ||
err = json.Unmarshal(got, &unmarshalled) | ||
require.NoError(t, err) | ||
test.validate(t, unmarshalled) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters