1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-16 04:24:56 +02:00

Adding internal/redis/key.go

This commit is contained in:
Henrik Hautakoski 2023-01-06 17:05:44 +01:00
parent 15b9a9804f
commit 61beca435c
2 changed files with 48 additions and 0 deletions

17
internal/redis/key.go Normal file
View file

@ -0,0 +1,17 @@
package redis
import (
"fmt"
)
// Key consists of a namespace and a channel.
// And is encoded to a string in this format: `<namespace>::<channel>`
type Key struct {
NS Namespace
Channel ChannelInterface
}
func (k Key) String() string {
return fmt.Sprintf("%s::%s", k.NS, k.Channel)
}

View file

@ -0,0 +1,31 @@
package redis
import "testing"
func TestKey_String(t *testing.T) {
type fields struct {
NS Namespace
Channel ChannelInterface
}
tests := []struct {
name string
fields fields
want string
}{
{"Empty", fields{NS: Namespace{}, Channel: Channel{}}, "ship.0000000000000000000000000000000000000000000000000000000000000000::"},
{"Transactions", fields{NS: Namespace{ChainID: "id"}, Channel: Channel{"transactions"}}, "ship.id::transactions"},
{"Nested", fields{NS: Namespace{ChainID: "id"}, Channel: Channel{"one.two"}}, "ship.id::one.two"},
{"Action", fields{NS: Namespace{ChainID: "id"}, Channel: ActionChannel{Contract: "mycontract"}}, "ship.id::actions.contract:mycontract"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
k := Key{
NS: tt.fields.NS,
Channel: tt.fields.Channel,
}
if got := k.String(); got != tt.want {
t.Errorf("Key.String() = %v, want %v", got, tt.want)
}
})
}
}