-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adding fuzz testing for common util (#688)
- Loading branch information
Showing
4 changed files
with
57 additions
and
5 deletions.
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
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
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,40 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func FuzzRandomInterval(f *testing.F) { | ||
testCases := []struct { | ||
interval string | ||
}{ | ||
{ | ||
interval: "13", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
f.Add(tc.interval) | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, interval string) { | ||
re := regexp.MustCompile(`^\d+(-\d+)?$`) | ||
intervals := strings.Split(interval, "-") | ||
err := RandomInterval(interval) | ||
|
||
if re.MatchString(interval) == false { | ||
assert.Error(t, err, "{\"errorCode\":\"GENERIC_ERROR\",\"reason\":\"could not parse CHAOS_INTERVAL env, bad input\"}") | ||
} | ||
|
||
num, _ := strconv.Atoi(intervals[0]) | ||
if num < 1 && err != nil { | ||
assert.Error(t, err, "{\"errorCode\":\"GENERIC_ERROR\",\"reason\":\"invalid CHAOS_INTERVAL env value, value below lower limit\"}") | ||
} else if num > 1 && err != nil { | ||
t.Errorf("Unexpected Error: %v", err) | ||
} | ||
}) | ||
} |
2 changes: 2 additions & 0 deletions
2
pkg/utils/common/testdata/fuzz/FuzzRandomInterval/711bbee1d16a50e2
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,2 @@ | ||
go test fuzz v1 | ||
string("2778") |