-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: omit empty packageVerificationCode from 2.2 JSON
Signed-off-by: Keith Zantow <[email protected]>
- Loading branch information
Showing
2 changed files
with
83 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,57 @@ | ||
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 string) | ||
}{ | ||
{ | ||
name: "include packageVerificationCode exclusions", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{ | ||
ExcludedFiles: []string{}, | ||
}, | ||
}, | ||
validate: func(t *testing.T, got string) { | ||
require.Contains(t, got, "packageVerificationCode") | ||
}, | ||
}, | ||
{ | ||
name: "include packageVerificationCode value", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{ | ||
Value: "1234", | ||
}, | ||
}, | ||
validate: func(t *testing.T, got string) { | ||
require.Contains(t, got, "packageVerificationCode") | ||
}, | ||
}, | ||
{ | ||
name: "omit empty packageVerificationCode", | ||
pkg: spdx.Package{ | ||
PackageVerificationCode: common.PackageVerificationCode{}, | ||
}, | ||
validate: func(t *testing.T, got string) { | ||
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) | ||
test.validate(t, string(got)) | ||
}) | ||
} | ||
} |
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