-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowflake_test.go
65 lines (44 loc) · 1.24 KB
/
snowflake_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
package snowflake
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"testing"
)
type test struct {
Snowflake Snowflake `json:"snowflake,omitempty"`
}
func TestParse(t *testing.T) {
require := require.New(t)
raw := "829388262825132092"
s, err := Parse(raw)
require.NoError(err)
fmt.Println(s)
}
func TestSnowflake_UnmarshalJSONWithInt(t *testing.T) {
require := require.New(t)
raw, test := "{\"snowflake\": 829388262825132092}", new(test)
err := json.Unmarshal([]byte(raw), &test)
require.NoError(err)
fmt.Println(test.Snowflake)
}
func TestSnowflake_UnmarshalJSONWithString(t *testing.T) {
require := require.New(t)
raw, test := "{\"snowflake\": \"829388262825132092\"}", new(test)
err := json.Unmarshal([]byte(raw), &test)
require.NoError(err)
fmt.Println(test.Snowflake)
}
func TestSnowflake_UnmarshalJSONWithEmptyString(t *testing.T) {
require := require.New(t)
raw, test := "{\"snowflake\": \"\"}", new(test)
err := json.Unmarshal([]byte(raw), &test)
require.NoError(err)
fmt.Println(test.Snowflake)
}
func TestSnowflake_UnmarshalJSONWithNonsense(t *testing.T) {
require := require.New(t)
raw, test := "{\"snowflake\": true}", new(test)
err := json.Unmarshal([]byte(raw), &test)
require.Error(err)
}