-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
38 lines (34 loc) · 931 Bytes
/
client_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
package zeversolar_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/axatol/go-zeversolar"
"github.com/stretchr/testify/require"
)
func TestClient(t *testing.T) {
for i, tt := range testcases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
mock := func(w http.ResponseWriter, r *http.Request) { w.Write(tt.raw) }
ts := httptest.NewServer(http.HandlerFunc(mock))
client := zeversolar.Client{Address: ts.URL}
actual, err := client.GetInverterData(context.Background())
if tt.parsed == nil {
require.Error(t, err)
require.Nil(t, actual)
} else {
require.NoError(t, err)
require.Equal(t, tt.parsed, actual)
}
})
}
}
func TestClientLive(t *testing.T) {
client := zeversolar.Client{Address: "http://192.168.1.44"}
actual, err := client.GetInverterData(context.Background())
require.NoError(t, err)
require.NotNil(t, actual)
t.Logf("%+v", *actual)
}