forked from litmuschaos/litmusctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fuzzer in Litmusctl (litmuschaos#210)
Signed-off-by: Saranya-jena <[email protected]>
- Loading branch information
1 parent
95fad15
commit 49ebc8b
Showing
3 changed files
with
46 additions
and
0 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
2 changes: 2 additions & 0 deletions
2
...FuzzGenerateRandomString/db3c85722c184874f5c5f7a0dc70931623063a57537f3add9bea423066303259
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 | ||
int(-82) |
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,41 @@ | ||
package utils | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func isValidString(s string) bool { | ||
// Define the set of valid characters | ||
validChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" | ||
|
||
// Iterate over each character in the string | ||
for _, char := range s { | ||
// Check if the character is not in the set of valid characters | ||
if !strings.ContainsRune(validChars, char) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func FuzzGenerateRandomString(f *testing.F) { | ||
f.Add(10) | ||
f.Fuzz(func(t *testing.T, n int) { | ||
randomString, err := GenerateRandomString(n) | ||
if err != nil && n > 0 { | ||
t.Errorf("Error generating random string: %v", err) | ||
} | ||
// Perform checks on the generated string | ||
// Check if the length matches the expected length | ||
if n >= 0 && len(randomString) != n { | ||
t.Errorf("Generated string length doesn't match expected length") | ||
} | ||
|
||
// Check if the string contains only valid characters | ||
if !isValidString(randomString) { | ||
t.Errorf("Generated string contains invalid characters") | ||
} | ||
}) | ||
|
||
} |