Skip to content

Commit

Permalink
test: simplify file tests
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
  • Loading branch information
fzipi committed Sep 23, 2024
1 parent b3232d5 commit 5b94d9a
Showing 1 changed file with 12 additions and 170 deletions.
182 changes: 12 additions & 170 deletions internal/quantitative/leipzig/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,183 +4,25 @@
package leipzig

import (
"reflect"
"github.com/stretchr/testify/suite"
"testing"

"github.com/coreruleset/go-ftw/experimental/corpus"
)

func TestFile_CacheDir(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath",
},
want: "cacheDir",
},
{
name: "Test 2",
fields: fields{
cacheDir: "cacheDir2",
filePath: "filePath2",
},
want: "cacheDir2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.CacheDir(); got != tt.want {
t.Errorf("CacheDir() = %v, want %v", got, tt.want)
}
})
}
type fileTestSuite struct {
suite.Suite
cache corpus.File
}

func TestFile_FilePath(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath",
},
want: "filePath",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.FilePath(); got != tt.want {
t.Errorf("FilePath() = %v, want %v", got, tt.want)
}
})
}
func TestFileSuite(t *testing.T) {
suite.Run(t, new(fileTestSuite))
}

func TestFile_WithCacheDir(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
type args struct {
cacheDir string
}
tests := []struct {
name string
fields fields
args args
want corpus.File
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir1",
filePath: "filePath",
},
args: args{
cacheDir: "cacheDir10",
},
want: File{
cacheDir: "cacheDir10",
filePath: "filePath",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.WithCacheDir(tt.args.cacheDir); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithCacheDir() = %v, want %v", got, tt.want)
}
})
}
}

func TestFile_WithFilePath(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
type args struct {
filePath string
}
tests := []struct {
name string
fields fields
args args
want corpus.File
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath1",
},
args: args{
filePath: "filePath2",
},
want: File{
cacheDir: "cacheDir",
filePath: "filePath2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.WithFilePath(tt.args.filePath); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithFilePath() = %v, want %v", got, tt.want)
}
})
}
}

func TestNewFile(t *testing.T) {
tests := []struct {
name string
want corpus.File
}{
{
name: "Test 1",
want: File{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewFile(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewFile() = %v, want %v", got, tt.want)
}
})
}
func (s *fileTestSuite) TestFile_CacheDir() {
f := NewFile()
f = f.WithCacheDir("cacheDir")
s.Require().Equal("cacheDir", f.CacheDir())
f = f.WithFilePath("filePath")
s.Require().Equal("filePath", f.FilePath())
}

0 comments on commit 5b94d9a

Please sign in to comment.