Skip to content
This repository was archived by the owner on Mar 22, 2025. It is now read-only.

Commit c45cedf

Browse files
committed
added some tests
1 parent 5aea0b9 commit c45cedf

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

ZigBeeValve/thing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func initTemplate() components.UnitAsset {
8282

8383
// var uat components.UnitAsset // this is an interface, which we then initialize
8484
uat := &UnitAsset{
85-
Name: "2",
85+
Name: "Template",
8686
Details: map[string][]string{"Location": {"Kitchen"}},
8787
Model: "",
8888
Period: 10,

ZigBeeValve/zigbee_test.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"net/http"
78
"strings"
89
"testing"
910
"time"
1011

12+
"github.com/sdoque/mbaigo/components"
1113
"github.com/sdoque/mbaigo/forms"
1214
)
1315

@@ -68,10 +70,10 @@ func (t mockTransport) RoundTrip(req *http.Request) (resp *http.Response, err er
6870

6971
////////////////////////////////////////////////////////////////////////////////
7072

71-
const thermostatDomain string = "http://localhost:port/api/apikey/sensors/thermostat_index/config"
72-
const plugDomain string = "http://localhost:port/api/apikey/lights/plug_index/config"
73+
const thermostatDomain string = "http://localhost:8870/api/B3AFB6415A/sensors/2/config"
74+
const plugDomain string = "http://localhost:8870/api/B3AFB6415A/lights/1/config"
7375

74-
func TestUnitAssetChanged(t *testing.T) {
76+
func TestUnitAsset(t *testing.T) {
7577

7678
// Don't understand how to check my own deConz API calls, will extend the test with this once i understand
7779
trans := newMockTransport()
@@ -82,10 +84,9 @@ func TestUnitAssetChanged(t *testing.T) {
8284
}
8385

8486
// Creates a single UnitAsset and assert it changes
85-
ua := UnitAsset{
86-
Setpt: 20.0,
87-
}
87+
ua := initTemplate().(*UnitAsset)
8888

89+
// Change Setpt
8990
ua.setSetPoint(f)
9091

9192
if ua.Setpt != 27.0 {
@@ -98,3 +99,49 @@ func TestUnitAssetChanged(t *testing.T) {
9899
t.Errorf("Expected number of api requests = 1, got %d requests", hits)
99100
}
100101
}
102+
103+
func TestGetters(t *testing.T) {
104+
ua := initTemplate().(*UnitAsset)
105+
106+
name := ua.GetName()
107+
if name != "Template" {
108+
t.Errorf("Expected name to be 2, instead got %s", name)
109+
}
110+
111+
services := ua.GetServices()
112+
if services == nil {
113+
t.Fatalf("Expected services not to be nil")
114+
}
115+
if services["setpoint"].Definition != "setpoint" {
116+
t.Errorf("Expected definition to be setpoint")
117+
}
118+
119+
details := ua.GetDetails()
120+
if details == nil {
121+
t.Fatalf("Details was nil, expected map")
122+
}
123+
if len(details["Location"]) == 0 {
124+
t.Fatalf("Location was nil, expected kitchen")
125+
}
126+
127+
if details["Location"][0] != "Kitchen" {
128+
t.Errorf("Expected location to be Kitchen")
129+
}
130+
131+
cervices := ua.GetCervices()
132+
if cervices != nil {
133+
t.Errorf("Expected no cervices")
134+
}
135+
}
136+
137+
func TestNewResource(t *testing.T) {
138+
ctx, cancel := context.WithCancel(context.Background())
139+
defer cancel()
140+
141+
var uac UnitAsset
142+
sys := components.NewSystem("testsys", ctx)
143+
servsTemp := []components.Service{}
144+
145+
ua, cleanup := newResource(uac, &sys, servsTemp)
146+
147+
}

0 commit comments

Comments
 (0)