mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
add test with and without local bridge
This commit is contained in:
parent
8d47851c84
commit
ba75d0b618
@ -1,36 +1,51 @@
|
|||||||
package hue
|
package hue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gosticks/go-hue-interface/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseLights(t *testing.T) {
|
func TestParseLights(t *testing.T) {
|
||||||
|
v := make(map[string]*Light)
|
||||||
target := make(map[string]*Light)
|
err := utils.CompareJSONDecode(LightsTestData, &v)
|
||||||
buffer := new(bytes.Buffer)
|
if err != nil {
|
||||||
// Remove all spaces
|
t.Fail()
|
||||||
json.Compact(buffer, []byte(LightsTestData))
|
}
|
||||||
bytes := buffer.Bytes()
|
}
|
||||||
// Unmarshal the data
|
|
||||||
json.Unmarshal(bytes, &target)
|
func TestBridgeLightsParse(t *testing.T) {
|
||||||
|
userID, okUser := os.LookupEnv("HUE_BRIDGE_USER")
|
||||||
// Marshal it again
|
addr, okAddr := os.LookupEnv("HUE_BRIDGE_ADDR")
|
||||||
outputData, _ := json.Marshal(target)
|
if !okAddr || !okUser {
|
||||||
|
fmt.Println("HUE_BRIDGE_USER and HUE_BRIDGE_ADDR must be set in env for this test to work")
|
||||||
old := string(bytes)
|
t.Fail()
|
||||||
new := string(outputData)
|
}
|
||||||
|
|
||||||
if old != new {
|
conf := &Config{
|
||||||
fmt.Println("String do not match!")
|
Username: userID,
|
||||||
fmt.Println("OLD: \n " + old)
|
BridgeAddr: addr,
|
||||||
fmt.Println("----------------------------- ")
|
BridgeAddrScheme: "http",
|
||||||
fmt.Println("NEW: \n " + new)
|
}
|
||||||
|
b := NewBridge(conf)
|
||||||
|
resp, respErr := b.getRawResponse(LightsEndpoint)
|
||||||
|
if respErr != nil {
|
||||||
|
t.Log(respErr)
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
lights, errLights := b.GetLights()
|
||||||
|
if errLights != nil {
|
||||||
|
t.Log(errLights)
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
errComp := utils.CompareStructToJSON(lights, string(resp))
|
||||||
|
if errComp != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
t.Log("Completed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const LightsTestData = `{
|
const LightsTestData = `{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user