github.com/CyCoreSystems/ari@v4.8.4+incompatible/rid/rid_test.go (about) 1 package rid 2 3 import ( 4 "strings" 5 "testing" 6 "time" 7 ) 8 9 func TestGeneric(t *testing.T) { 10 11 a := New("") 12 t.Logf("Generated ID: (%s)", a) 13 14 b := New("") 15 t.Logf("Generated ID: (%s)", b) 16 17 if a == b { 18 t.Errorf("consecutive IDs do not differ (%s) (%s)", a, b) 19 return 20 } 21 22 } 23 24 func TestKind(t *testing.T) { 25 a := New(Channel) 26 t.Logf("Generated channel ID: (%s)", a) 27 28 if !strings.HasSuffix(a, "-ch") { 29 t.Errorf("failed to apply proper resource suffix (%s); should have be -ch", a) 30 31 } 32 } 33 34 func TestKindClipping(t *testing.T) { 35 a := New("hello") 36 t.Logf("Generated hello ID: (%s)", a) 37 38 if !strings.HasSuffix(a, "-he") { 39 t.Errorf("failed to apply proper resource suffix (%s); should have been -he", a) 40 41 } 42 } 43 44 func TestTimestamp(t *testing.T) { 45 a := New(Channel) 46 47 ts, err := Timestamp(a) 48 if err != nil { 49 t.Error("failed to parse channel resource ID", err) 50 return 51 } 52 t.Log("parsed timestamp", ts.String()) 53 54 if time.Since(ts) > time.Second { 55 t.Error("timestamp is older than a second") 56 } 57 if time.Until(ts) > time.Second { 58 t.Error("timestamp is in the future") 59 } 60 } 61 62 func TestTimestampGeneric(t *testing.T) { 63 a := New("") 64 65 ts, err := Timestamp(a) 66 if err != nil { 67 t.Error("failed to parse channel resource ID", err) 68 return 69 } 70 t.Log("parsed timestamp", ts.String()) 71 72 if time.Since(ts) > time.Second { 73 t.Error("timestamp is older than a second") 74 } 75 if time.Until(ts) > time.Second { 76 t.Error("timestamp is in the future") 77 } 78 }