-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
32 lines (26 loc) · 910 Bytes
/
integration_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
package shelly_test
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
shelly "github.com/jcodybaker/go-shelly"
"github.com/mongoose-os/mos/common/mgrpc"
)
func GetCallWithVerify(t *testing.T, req shelly.RPCRequestBody, respBody interface{}) {
ctx := context.Background()
c, err := mgrpc.New(ctx, "http://192.168.1.23/rpc", mgrpc.UseHTTPPost())
require.NoError(t, err)
defer c.Disconnect(ctx)
respFrame, err := shelly.Do(ctx, c, nil, req, respBody)
require.NoError(t, err)
fmt.Println(string(respFrame.Response))
// The reencoded JSON *SHOULD* match.
// NOTE: in practice there seem to be some undocumented fields and inconsistency in what
// is NULL and what is omited when NULL.
jsonOut, err := json.Marshal(respBody)
require.NoError(t, err)
assert.JSONEq(t, string(respFrame.Response), string(jsonOut))
}