-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcard_source_test.go
53 lines (50 loc) · 1.68 KB
/
card_source_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
package riff
import (
"fmt"
"testing"
)
func TestCardSource(t *testing.T) {
sid := newID()
cid := newID()
cid2 := newID()
data := "1111"
context := map[string]string{
"aaa": "bbb",
}
basecardSource := &BaseCardSource{
SID: sid,
CType: builtInCardType,
CIDMap: map[CardID]CardKey{},
Data: data,
}
basecardSource.SetCardIDMap("card", CardID(cid))
var cardSource CardSource = basecardSource
if cardSource.SourceID() != sid {
t.Fatalf("cardSource id [%s] != [%s]", cardSource.SourceID(), sid)
}
if cardSource.CardType() != builtInCardType {
t.Fatalf("cardSource cardType [%s] != [%s]", cardSource.CardType(), builtInCardType)
}
if cardSource.GetSourceData() != data {
t.Fatalf("cardSource SourceData [%s] != [%s]", cardSource.GetSourceData(), data)
}
for key, value := range cardSource.GetContext() {
if context[key] != value {
t.Fatalf("cardSource context key [%s] value [%s] != [%s]", key, value, context[key])
}
}
if cardSource.GetCardIDMap()["card"] != cid {
t.Fatalf("cardSource CardIDMap key card [%s] != [%s]", cardSource.GetCardIDMap()["card"], cid)
}
cardSource.SetCardIDMap("card", CardID(cid2))
if cardSource.GetCardIDMap()["card"] != cid2 {
t.Fatalf("cardSource SetCardIDMap key card [%s] != [%s]", cardSource.GetCardIDMap()["card"], cid)
}
if len(cardSource.GetCardIDs()) != 1 {
t.Logf("current cardIDs is [%s]", fmt.Sprint(cardSource.GetCardIDs()))
t.Fatalf("cardSource GetCardIDs cardIDs len [%s] != 1", fmt.Sprint(len(cardSource.GetCardIDs())))
}
if cardSource.GetCardIDs()[0] != cid2 {
t.Fatalf("cardSource GetCardIDs cardIDs first [%s] != [%s] ", cardSource.GetCardIDs()[0], cid2)
}
}