-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
65 lines (51 loc) · 1.66 KB
/
config_test.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"net/url"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestBuildingAConfig(t *testing.T) {
fileReader = SyswardFileReader{}
Convey("Given I have a valid configuration", t, func() {
configSettings := NewConfig("config.json")
config = SyswardConfig{AgentConfig: configSettings}
//Convey("The host should be set", func() {
// So(config.Config().Host, ShouldEqual, "192.168.1.57:3000")
//})
Convey("The protocol should be http", func() {
So(config.Config().Protocol, ShouldEqual, "http")
})
Convey("The interval should be set", func() {
So(config.Config().Interval, ShouldEqual, "15s")
})
Convey("The ApiKey should be set", func() {
So(config.Config().ApiKey, ShouldNotBeNil)
})
})
}
func TestURLBuilding(t *testing.T) {
uid := "abc"
fileReader = SyswardFileReader{}
Convey("Given I have a valid config", t, func() {
configSettings := NewConfig("config.json")
config = SyswardConfig{AgentConfig: configSettings}
Convey("fetchJobUrl should be a valid URL", func() {
_url := config.fetchJobUrl(uid)
u, _ := url.Parse(_url)
So(u.Path, ShouldEqual, "/api/v1/jobs")
So(u.RawQuery, ShouldContainSubstring, "uid=abc&api_key=")
})
Convey("fetchJobPostbackUrl should be a valid URL", func() {
_url := config.fetchJobPostbackUrl()
u, _ := url.Parse(_url)
So(u.Path, ShouldEqual, "/api/v1/postback")
So(u.RawQuery, ShouldContainSubstring, "api_key=")
})
Convey("agentCheckinUrl should be a valid URL", func() {
_url := config.agentCheckinUrl()
u, _ := url.Parse(_url)
So(u.Path, ShouldEqual, "/api/v1/agent")
So(u.RawQuery, ShouldContainSubstring, "api_key=")
})
})
}