mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
api/channel.go: Adding Channel.Type()
This commit is contained in:
parent
47dda7a3f4
commit
9e586d879d
2 changed files with 27 additions and 0 deletions
|
|
@ -19,6 +19,13 @@ func (c Channel) String() string {
|
|||
return c.Format("/")
|
||||
}
|
||||
|
||||
func (c Channel) Type() string {
|
||||
if len(c) > 0 {
|
||||
return c[0]
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// Check if two channels are equal
|
||||
func (c Channel) Is(other Channel) bool {
|
||||
if len(c) != len(other) {
|
||||
|
|
|
|||
|
|
@ -90,6 +90,26 @@ func TestChannel_String(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestChannel_Type(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
c Channel
|
||||
want string
|
||||
}{
|
||||
{"Empty", Channel{}, "unknown"},
|
||||
{"Heartbeat", HeartbeatChannel, "heartbeat"},
|
||||
{"Transaction", TransactionChannel, "transactions"},
|
||||
{"Actions", ActionChannel{}.Channel(), "actions"},
|
||||
}
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue