From 1cdcb73ce408d11a49140ca260386aba7769c2d8 Mon Sep 17 00:00:00 2001 From: Sascha Steinbiss Date: Mon, 15 Mar 2021 19:28:41 +0100 Subject: [PATCH] more tests --- communityid_test.go | 26 ++++++++++++++++++++++++++ communityid_v1_test.go | 2 ++ 2 files changed, 28 insertions(+) create mode 100644 communityid_test.go diff --git a/communityid_test.go b/communityid_test.go new file mode 100644 index 0000000..6b03306 --- /dev/null +++ b/communityid_test.go @@ -0,0 +1,26 @@ +package gommunityid + +import ( + "testing" +) + +func TestCommunityIDMake(t *testing.T) { + cid, err := GetCommunityIDByVersion(1, 42) + if err != nil { + t.Fatal(err) + } + cidv1, ok := cid.(CommunityIDv1) + if !ok { + t.Fatal("can't assert expected type") + } + if cidv1.Seed != 42 { + t.Fatalf("wrong seed: %d", cidv1.Seed) + } +} + +func TestCommunityIDMakeFail(t *testing.T) { + _, err := GetCommunityIDByVersion(23, 42) + if err == nil { + t.Fatal(err) + } +} diff --git a/communityid_v1_test.go b/communityid_v1_test.go index 4834968..fe1ba32 100644 --- a/communityid_v1_test.go +++ b/communityid_v1_test.go @@ -1,6 +1,7 @@ package gommunityid import ( + "fmt" "net" "testing" @@ -31,6 +32,7 @@ func verifyTuples(t *testing.T, ts []testSet, mf makeFunc) { assert.Equal(t, tset.Base64Seed0, cid0.CalcBase64(ft)) assert.Equal(t, tset.HexSeed0, cid0.CalcHex(ft)) assert.Equal(t, tset.Base64Seed1, cid1.CalcBase64(ft)) + assert.Equal(t, tset.HexSeed0, fmt.Sprintf("1:%x", cid0.Calc(ft))) } }