Skip to content

Commit 6f7aea9

Browse files
committed
Minor fixes to static discovery listeners
1 parent 2507e3c commit 6f7aea9

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

discovery/static_discovery.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ func (d *StaticDiscovery) ParseConfig(filename string) ([]*Target, error) {
104104
}
105105

106106
var targets []*Target
107-
json.Unmarshal(file, &targets)
107+
err = json.Unmarshal(file, &targets)
108+
if err != nil {
109+
return nil, fmt.Errorf("Unable to unmarshal Target: %s", err)
110+
}
108111

109112
// Have to loop with traditional 'for' loop so we can modify entries
110113
for _, target := range targets {

discovery/static_discovery_test.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,21 @@ func Test_ParseConfig(t *testing.T) {
3232
})
3333

3434
Convey("Applies hostnames to services", func() {
35-
parsed, _ := disco.ParseConfig(STATIC_JSON)
35+
parsed, err := disco.ParseConfig(STATIC_JSON)
36+
So(err, ShouldBeNil)
37+
So(len(parsed), ShouldEqual, 1)
3638
So(parsed[0].Service.Hostname, ShouldEqual, hostname)
3739
})
3840

3941
Convey("Uses the given hostname when specified", func() {
4042
parsed, _ := disco.ParseConfig(STATIC_HOSTNAMED_JSON)
43+
So(len(parsed), ShouldEqual, 1)
4144
So(parsed[0].Service.Hostname, ShouldEqual, "chaucer")
4245
})
4346

4447
Convey("Assigns the default IP address when a port doesn't have one", func() {
4548
parsed, _ := disco.ParseConfig(STATIC_JSON)
49+
So(len(parsed), ShouldEqual, 1)
4650
So(parsed[0].Service.Ports[0].IP, ShouldEqual, ip)
4751
})
4852
})
@@ -81,17 +85,23 @@ func Test_Listeners(t *testing.T) {
8185
Convey("Listeners()", t, func() {
8286
ip := "127.0.0.1"
8387
disco := NewStaticDiscovery(STATIC_JSON, ip)
84-
tgt1 := &Target{
85-
Service: service.Service{Name: "beowulf", ID: "asdf"},
86-
ListenPort: 10000,
87-
}
88-
tgt2 := &Target{
89-
Service: service.Service{Name: "hrothgar", ID: "abba"},
90-
ListenPort: 11000,
91-
}
92-
disco.Targets = []*Target{tgt1, tgt2}
88+
89+
Convey("Loads targets from the config", func() {
90+
disco.Run(director.NewFreeLooper(director.ONCE, nil))
91+
So(len(disco.Targets), ShouldEqual, 1)
92+
})
9393

9494
Convey("Returns all listeners extracted from Targets", func() {
95+
tgt1 := &Target{
96+
Service: service.Service{Name: "beowulf", ID: "asdf"},
97+
ListenPort: 10000,
98+
}
99+
tgt2 := &Target{
100+
Service: service.Service{Name: "hrothgar", ID: "abba"},
101+
ListenPort: 11000,
102+
}
103+
disco.Targets = []*Target{tgt1, tgt2}
104+
95105
listeners := disco.Listeners()
96106

97107
expected0 := ChangeListener{

fixtures/static.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"ProxyMode": "http"
1414
},
15+
"ListenPort": 9999,
1516
"Check": {
1617
"Type": "HttpGet",
1718
"Args": "http://:10234/"

0 commit comments

Comments
 (0)