generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparams_test.go
66 lines (56 loc) · 1.67 KB
/
params_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
package datastore
import (
"bytes"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestQueryParams_UnmarshalQueryParams will test the db Scanner of the QueryParams model
func TestQueryParams_UnmarshalQueryParams(t *testing.T) {
t.Parallel()
t.Run("nil value", func(t *testing.T) {
m, err := UnmarshalQueryParams(nil)
require.NoError(t, err)
assert.Equal(t, QueryParams{}, m)
})
t.Run("empty string", func(t *testing.T) {
m, err := UnmarshalQueryParams("\"\"")
require.Error(t, err)
assert.Equal(t, QueryParams{}, m)
})
t.Run("empty string - incorrectly coded", func(t *testing.T) {
m, err := UnmarshalQueryParams("")
require.Error(t, err)
assert.Equal(t, QueryParams{}, m)
})
t.Run("object", func(t *testing.T) {
var data map[string]interface{}
err := json.Unmarshal([]byte(`{"page": 100}`), &data)
require.NoError(t, err)
var m QueryParams
m, err = UnmarshalQueryParams(data)
require.NoError(t, err)
assert.Equal(t, QueryParams{Page: 100}, m)
})
}
// TestMetadata_MarshalMetadata will test the db Valuer of the Metadata model
func TestMetadata_MarshalMetadata(t *testing.T) {
t.Parallel()
t.Run("empty object", func(t *testing.T) {
q := QueryParams{}
writer := MarshalQueryParams(q)
require.NotNil(t, writer)
b := bytes.NewBufferString("")
writer.MarshalGQL(b)
assert.Equal(t, "null", b.String())
})
t.Run("map present", func(t *testing.T) {
q := QueryParams{Page: 11, PageSize: 35}
writer := MarshalQueryParams(q)
require.NotNil(t, writer)
b := bytes.NewBufferString("")
writer.MarshalGQL(b)
assert.Equal(t, `{"page":11,"page_size":35}`+"\n", b.String())
})
}