mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
149 lines
3.8 KiB
Go
149 lines
3.8 KiB
Go
package api
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestChannel_Append(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
arg string
|
|
obj Channel
|
|
expected Channel
|
|
}{
|
|
{"One", "one", Channel{}, Channel{"one"}},
|
|
{"More", "more", Channel{"one", "two"}, Channel{"one", "two", "more"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.obj.Append(tt.arg)
|
|
if reflect.DeepEqual(tt.obj, tt.expected) == false {
|
|
t.Errorf("Channel.Append() expected %v, got %v", tt.expected, tt.obj)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChannel_Is(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
a Channel
|
|
b Channel
|
|
want bool
|
|
}{
|
|
{"Empty valid", Channel{}, Channel{}, true},
|
|
{"Valid #1", Channel{"one"}, Channel{"one"}, true},
|
|
{"Valid #2", Channel{"one", "two"}, Channel{"one", "two"}, true},
|
|
{"Invalid #1", Channel{"one"}, Channel{"one", "two"}, false},
|
|
{"Invalid #2", Channel{"one", "three"}, Channel{"one", "two"}, false},
|
|
{"Invalid #3", Channel{"two", "one"}, Channel{"one", "two"}, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.a.Is(tt.b); got != tt.want {
|
|
t.Errorf("a.Is(b) = %v, want %v", got, tt.want)
|
|
}
|
|
|
|
if got := tt.b.Is(tt.a); got != tt.want {
|
|
t.Errorf("b.Is(a) = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChannel_Format(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
delim string
|
|
want string
|
|
c Channel
|
|
}{
|
|
{"Empty", ":", "", Channel{}},
|
|
{"Alot#1", "-", "one-two-three", Channel{"one", "two", "three"}},
|
|
{"Alot#2", ":", "first:second", Channel{"first", "second"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.c.Format(tt.delim); got != tt.want {
|
|
t.Errorf("Channel.Format() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChannel_String(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
want string
|
|
c Channel
|
|
}{
|
|
{"Empty", "", Channel{}},
|
|
{"Alot", "one/two/three", Channel{"one", "two", "three"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.c.String(); got != tt.want {
|
|
t.Errorf("Channel.String() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChannel_Type(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
want string
|
|
c Channel
|
|
}{
|
|
{"Empty", "unknown", Channel{}},
|
|
{"Heartbeat", "heartbeat", HeartbeatChannel},
|
|
{"Transaction", "transactions", TransactionChannel},
|
|
{"Actions", "actions", ActionChannel{}.Channel()},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.c.Type(); got != tt.want {
|
|
t.Errorf("Channel.Type() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAction_Channel(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
action ActionChannel
|
|
want Channel
|
|
}{
|
|
{"Empty", ActionChannel{}, Channel{"actions"}},
|
|
{"Contract", ActionChannel{Contract: "mycontract"}, Channel{"actions", "contract", "mycontract"}},
|
|
{"Action", ActionChannel{Name: "myaction"}, Channel{"actions", "name", "myaction"}},
|
|
{"ContractAndName", ActionChannel{Contract: "mycontract", Name: "myaction"}, Channel{"actions", "contract", "mycontract", "name", "myaction"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.action.Channel(); !got.Is(tt.want) {
|
|
t.Errorf("ActionChannel.String() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTableDelta_Channel(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
action TableDeltaChannel
|
|
want Channel
|
|
}{
|
|
{"Empty", TableDeltaChannel{}, Channel{"tabledeltas"}},
|
|
{"Contract", TableDeltaChannel{Name: "delta_name"}, Channel{"tabledeltas", "name", "delta_name"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.action.Channel(); !got.Is(tt.want) {
|
|
t.Errorf("TableDeltaChannel.String() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|