mirror of
https://github.com/wahyd4/redhat.git
synced 2026-08-09 04:25:53 +10:00
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package redhat
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestFromFile(t *testing.T) {
|
|
type args struct {
|
|
filePath string
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantNonNilFileAnalyser bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "can init file analyser",
|
|
args: args{filePath: "./test_files/valid_input.txt"},
|
|
wantNonNilFileAnalyser: true,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "fail to init file analyser due to file doesn't not exist",
|
|
args: args{filePath: "./non_exist_file"},
|
|
wantNonNilFileAnalyser: false,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := InitFromFile(tt.args.filePath)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("InitFromFile() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if (got != nil) != tt.wantNonNilFileAnalyser {
|
|
t.Errorf("InitFromFile() got = %v, want %v", got != nil, tt.wantNonNilFileAnalyser)
|
|
}
|
|
})
|
|
}
|
|
}
|