Add some tests (#479)

This commit is contained in:
Massimo Prencipe 2022-01-22 19:52:27 +02:00 committed by GitHub
parent 2fdbd25655
commit 415ec0fd23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 0 deletions

26
pkg/ffuf/util_test.go Normal file
View file

@ -0,0 +1,26 @@
package ffuf
import (
"math/rand"
"testing"
)
func TestRandomString(t *testing.T) {
length := 1 + rand.Intn(65535)
str := RandomString(length)
if len(str) != length {
t.Errorf("Length of generated string was %d, was expecting %d", len(str), length)
}
}
func TestUniqStringSlice(t *testing.T) {
slice := []string{"foo", "foo", "bar", "baz", "baz", "foo", "baz", "baz", "foo"}
expectedLength := 3
uniqSlice := UniqStringSlice(slice)
if len(uniqSlice) != expectedLength {
t.Errorf("Length of slice was %d, was expecting %d", len(uniqSlice), expectedLength)
}
}

View file

@ -0,0 +1,21 @@
package input
import (
"testing"
)
func TestStripCommentsIgnoresCommentLines(t *testing.T) {
text, _ := stripComments("# text")
if text != "" {
t.Errorf("Returned text was not a blank string")
}
}
func TestStripCommentsStripsCommentAfterText(t *testing.T) {
text, _ := stripComments("text # comment")
if text != "text" {
t.Errorf("Comment was not stripped or pre-comment text was not returned")
}
}

View file

@ -0,0 +1,44 @@
package output
import (
"reflect"
"testing"
"time"
"github.com/ffuf/ffuf/pkg/ffuf"
)
func TestToCSV(t *testing.T) {
result := ffuf.Result{
Input: map[string][]byte{"x": {66}},
Position: 1,
StatusCode: 200,
ContentLength: 3,
ContentWords: 4,
ContentLines: 5,
ContentType: "application/json",
RedirectLocation: "http://no.pe",
Url: "http://as.df",
Duration: time.Duration(123),
ResultFile: "resultfile",
Host: "host",
}
csv := toCSV(result)
if !reflect.DeepEqual(csv, []string{
"B",
"http://as.df",
"http://no.pe",
"1",
"200",
"3",
"4",
"5",
"application/json",
"123ns",
"resultfile"}) {
t.Errorf("CSV was not generated in expected format")
}
}