Skip to content

Commit

Permalink
feat(snowflake): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DasPoet committed Aug 26, 2021
1 parent 6b25961 commit 45fbbf8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions snowflake_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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_UnmarshalJSONWithNonsense(t *testing.T) {
require := require.New(t)

raw, test := "{\"snowflake\": true}", new(test)

err := json.Unmarshal([]byte(raw), &test)
require.Error(err)
}

0 comments on commit 45fbbf8

Please sign in to comment.