-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a5025d
commit 7b8b0a5
Showing
7 changed files
with
157 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
hue "github.com/collinux/gohue" | ||
"github.com/mitchellrj/hue_exporter/test" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"testing" | ||
) | ||
|
||
func TestGroupCollector(t *testing.T) { | ||
bridge := test.NewStubBridge().WithGroups([]hue.Group{ | ||
hue.Group{ | ||
Action: hue.Action{ | ||
Bri: 256, | ||
Hue: 100, | ||
Sat: 80, | ||
}, | ||
State: struct { | ||
AllOn bool `json:"all_on"` | ||
AnyOn bool `json:"any_on"` | ||
}{ | ||
AllOn: true, | ||
AnyOn: true, | ||
}, | ||
Type: "Room", | ||
Name: "Living room", | ||
}, | ||
}) | ||
|
||
metrics := make(chan prometheus.Metric, 5) | ||
collector := NewGroupCollector("test_hue", bridge) | ||
collector.Collect(metrics) | ||
close(metrics) | ||
|
||
for metric := range metrics { | ||
t.Logf("%v\n", metric) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
hue "github.com/collinux/gohue" | ||
) | ||
|
||
type APIFailure int | ||
|
||
const ( | ||
LoginFailure APIFailure = iota | ||
GetGroupsFailure | ||
GetLightsFailure | ||
GetSensorsFailure | ||
) | ||
|
||
type stubHueBridge struct { | ||
ctx context.Context | ||
lights []hue.Light | ||
groups []hue.Group | ||
sensors []hue.Sensor | ||
} | ||
|
||
func NewStubBridge() *stubHueBridge { | ||
return &stubHueBridge{ | ||
ctx: context.Background(), | ||
} | ||
} | ||
|
||
func (s *stubHueBridge) WithFailure(fail APIFailure) *stubHueBridge { | ||
s.ctx = context.WithValue(s.ctx, fail, true) | ||
return s | ||
} | ||
|
||
func (s *stubHueBridge) WithGroups(groups []hue.Group) *stubHueBridge { | ||
s.groups = groups | ||
return s | ||
} | ||
|
||
func (s *stubHueBridge) WithLights(lights []hue.Light) *stubHueBridge { | ||
s.lights = lights | ||
return s | ||
} | ||
|
||
func (s *stubHueBridge) WithSensors(sensors []hue.Sensor) *stubHueBridge { | ||
s.sensors = sensors | ||
return s | ||
} | ||
|
||
func (s *stubHueBridge) Login(apiKey string) error { | ||
if val, ok := s.ctx.Value(LoginFailure).(bool); ok && val { | ||
return errors.New("Deliberate login failure") | ||
} | ||
return nil | ||
} | ||
|
||
func (s *stubHueBridge) GetAllGroups() ([]hue.Group, error) { | ||
if val, ok := s.ctx.Value(GetGroupsFailure).(bool); ok && val { | ||
return []hue.Group{}, errors.New("Deliberate get groups failure") | ||
} | ||
return s.groups, nil | ||
} | ||
|
||
func (s *stubHueBridge) GetAllLights() ([]hue.Light, error) { | ||
if val, ok := s.ctx.Value(GetLightsFailure).(bool); ok && val { | ||
return []hue.Light{}, errors.New("Deliberate get lights failure") | ||
} | ||
return s.lights, nil | ||
} | ||
|
||
func (s *stubHueBridge) GetAllSensors() ([]hue.Sensor, error) { | ||
if val, ok := s.ctx.Value(GetSensorsFailure).(bool); ok && val { | ||
return []hue.Sensor{}, errors.New("Deliberate get sensors failure") | ||
} | ||
return s.sensors, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package main | ||
|
||
const VERSION = "0.1.0" | ||
const VERSION = "0.2.0" |