-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
47 lines (45 loc) · 1.43 KB
/
config_test.go
File metadata and controls
47 lines (45 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"os"
"reflect"
"testing"
)
func TestGetConfig(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want *Config
wantErr bool
}{
{"Good01", args{"testfiles/Good01.yml"}, &Config{"punkbot", []string{"punkbot", "running"}, "my.jetstream.example.com", false, "SomePassword"}, false},
{"Good02", args{"testfiles/Good02.json"}, &Config{"punkbotjson", []string{"punkbot", "running", "JSON"}, "my.jetstream.example.com", false, "SomePassword"}, false},
{"Good03", args{"testfiles/Good03.yml"}, &Config{"punkbot", []string{"punkbot", "running"}, "my.jetstream.example.com", false, "SomePassword"}, false},
{"MalformedJson", args{"testfiles/Malformed.json"}, nil, true},
{"NoFile", args{"testfiles/NoFile.yml"}, nil, true},
{"NoPassword", args{"testfiles/NoPassword.yml"}, nil, true},
{"NoTerms", args{"testfiles/NoTerms.yml"}, nil, true},
}
for _, tt := range tests {
if tt.name == "NoPassword" {
os.Unsetenv("PUNKBOT_PASSWORD")
} else {
os.Setenv("PUNKBOT_PASSWORD", "SomePassword")
}
t.Run(tt.name, func(t *testing.T) {
got, err := GetConfig(tt.args.path)
if (err != nil) != tt.wantErr {
//debug line
t.Errorf("%s", err.Error())
//end debug
t.Errorf("GetConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetConfig() = %v, want %v", got, tt.want)
}
})
}
}