aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Naveen <42328488+neilnaveen@users.noreply.github.com>2023-02-16 10:00:04 -0600
committerGitHub <noreply@github.com>2023-02-16 11:00:04 -0500
commit105e17fd98ed1fab33b68c57158920a23aad2fda (patch)
treee1bde1071e270ed40e3a0e0f24b871a741683140
parente233b61b3c18500fda4a21ad8bb9726c3279f670 (diff)
downloadspdx-tools-105e17fd98ed1fab33b68c57158920a23aad2fda.tar.gz
Included fuzzing for utils (#189)
Signed-off-by: Neil Naveen <42328488+neilnaveen@users.noreply.github.com>
-rw-r--r--.github/workflows/build.yml2
-rw-r--r--.gitignore1
-rw-r--r--Makefile11
-rw-r--r--utils/filesystem_test.go6
-rw-r--r--utils/verification_test.go21
5 files changed, 40 insertions, 1 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e739d7b..0e963f4 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -11,7 +11,7 @@ jobs:
with:
go-version: '1.18'
- name: Run tests
- run: go test -v -covermode=count -coverprofile=profile.cov ./...
+ run: make test
- name: Send coverage report to coveralls
uses: shogo82148/actions-goveralls@v1
with:
diff --git a/.gitignore b/.gitignore
index 38da0f8..042880d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@
.DS_Store
scratch/*
*.swp
+profile.cov
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ec42b61
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+.PHONY: test
+test: unit fuzz
+
+.PHONY: unit
+unit:
+ go test -v -covermode=count -coverprofile=profile.cov ./...
+
+.PHONY: fuzz
+fuzz:
+ go test -v -run=Fuzz -fuzz=FuzzShouldIgnore ./utils -fuzztime=10s
+ go test -v -run=Fuzz -fuzz=FuzzPackageCanGetVerificationCode ./utils -fuzztime=10s
diff --git a/utils/filesystem_test.go b/utils/filesystem_test.go
index 70e1291..d623c54 100644
--- a/utils/filesystem_test.go
+++ b/utils/filesystem_test.go
@@ -3,6 +3,7 @@
package utils
import (
+ "strings"
"testing"
)
@@ -224,3 +225,8 @@ func TestFilesystemExcludesForIgnoredPaths(t *testing.T) {
}
}
+func FuzzShouldIgnore(f *testing.F) {
+ f.Fuzz(func(t *testing.T, fileName string, pathsIgnored string) {
+ ShouldIgnore(fileName, strings.Fields(pathsIgnored))
+ })
+}
diff --git a/utils/verification_test.go b/utils/verification_test.go
index e389613..02f26f6 100644
--- a/utils/verification_test.go
+++ b/utils/verification_test.go
@@ -3,6 +3,7 @@
package utils
import (
+ "strings"
"testing"
"github.com/spdx/tools-golang/spdx"
@@ -170,3 +171,23 @@ func TestPackageGetVerificationCodeFailsIfNilFileInSlice(t *testing.T) {
t.Fatalf("expected non-nil error, got nil")
}
}
+func FuzzPackageCanGetVerificationCode(f *testing.F) {
+ f.Fuzz(func(t *testing.T, filename string, fileSPDXIdentifier string, checksums string) {
+ checks := []common.Checksum{}
+ for _, check := range strings.Fields(checksums) {
+ checks = append(checks, common.Checksum{Algorithm: common.SHA1, Value: check})
+ }
+ files := []*spdx.File{
+ {
+ FileName: filename,
+ FileSPDXIdentifier: common.ElementID(fileSPDXIdentifier),
+ Checksums: checks,
+ },
+ }
+
+ _, err := GetVerificationCode(files, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ })
+}