-
Notifications
You must be signed in to change notification settings - Fork 2
/
equipment_test.go
97 lines (77 loc) · 2.31 KB
/
equipment_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package solaredge_test
import (
"context"
"github.com/clambin/solaredge"
"github.com/clambin/solaredge/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"net/http"
"os"
"testing"
"time"
)
func TestClient_Equipment_E2E(t *testing.T) {
apikey := os.Getenv("SOLAREDGE_APIKEY")
if apikey == "" {
t.Skip("SOLAREDGE_APIKEY not set. Skipping")
}
c := solaredge.Client{Token: apikey}
ctx := context.Background()
sites, err := c.GetSites(ctx)
require.NoError(t, err)
for _, site := range sites {
inverters, err := site.GetInverters(ctx)
require.NoError(t, err)
end := time.Now()
start := end.Add(-24 * time.Hour)
for _, inverter := range inverters {
telemetry, err := inverter.GetTelemetry(ctx, start, end)
require.NoError(t, err)
assert.NotEmpty(t, telemetry)
_, err = site.GetChangeLog(ctx, inverter.SerialNumber)
require.NoError(t, err)
}
inventory, err := site.GetInventory(ctx)
require.NoError(t, err)
for _, inverter := range inventory.Inverters {
telemetry, err := inverter.GetTelemetry(ctx, start, end)
require.NoError(t, err)
assert.NotEmpty(t, telemetry)
_, err = site.GetChangeLog(ctx, inverter.SN)
require.NoError(t, err)
}
}
}
func TestSite_GetInverters(t *testing.T) {
c := solaredge.Client{Token: "1234"}
c.HTTPClient = &http.Client{Transport: &testutil.Server{Token: "1234"}}
ctx := context.Background()
sites, err := c.GetSites(ctx)
require.NoError(t, err)
require.Len(t, sites, 1)
inverters, err := sites[0].GetInverters(ctx)
require.NoError(t, err)
assert.NotZero(t, inverters)
}
func TestSite_GetInventory(t *testing.T) {
c := solaredge.Client{Token: "1234"}
c.HTTPClient = &http.Client{Transport: &testutil.Server{Token: "1234"}}
ctx := context.Background()
sites, err := c.GetSites(ctx)
require.NoError(t, err)
require.Len(t, sites, 1)
inventory, err := sites[0].GetInventory(ctx)
require.NoError(t, err)
assert.NotZero(t, inventory)
}
func TestSite_GetChangeLog(t *testing.T) {
c := solaredge.Client{Token: "1234"}
c.HTTPClient = &http.Client{Transport: &testutil.Server{Token: "1234"}}
ctx := context.Background()
sites, err := c.GetSites(ctx)
require.NoError(t, err)
require.Len(t, sites, 1)
changelog, err := sites[0].GetChangeLog(ctx, "SN1234")
require.NoError(t, err)
assert.NotZero(t, changelog)
}