Skip to content

Commit

Permalink
Merge pull request #77 from steffenfritz/add_tests
Browse files Browse the repository at this point in the history
added fuzzing test for CreateFileTroveDB
  • Loading branch information
steffenfritz authored May 16, 2024
2 parents bc545e5 + 6a464cc commit 68507ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3'
env:
VERSION: 1.0.0-DEV-16
CGO_ENABLED: "1"

tasks:
build:
cmds:
- go build -gcflags="-m" -buildmode=pie -ldflags "-X main.Version=$VERSION -X main.Build={{.GIT_COMMIT}} -w -s"
vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h
test:
cmds:
- go test -v
fuzz:
cmds:
# workaround with ld_cla needed on MacOS due to a bug in Apples new linker: https://github.com/golang/go/issues/65169
# update 2024-05-15: With the latest MacOS update 14.5 the legacy linker is not available anymore
#- go test -fuzz=Fuzz -test.fuzztime 10s -ldflags=-extldflags=-Wl,-ld_cla
- go test -fuzz=Fuzz -test.fuzztime 10s
12 changes: 12 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ func TestCreateFileTroveDB(t *testing.T) {
println("Could not remove test file: filetrove.db")
}
}

// FuzzCreateFileTroveDB fuzzes three input string values
func FuzzCreateFileTroveDB(f *testing.F) {
f.Fuzz(func(t *testing.T, a string, b string, c string) {
CreateFileTroveDB(a, b, c)
err := os.Remove(a)
if err != nil {
println("Could not remove test file")
}

})
}

0 comments on commit 68507ba

Please sign in to comment.