mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-04 12:03:41 +02:00
transport/channel.go: Add Format()
This commit is contained in:
parent
08c84d81ca
commit
f76290f299
2 changed files with 25 additions and 1 deletions
|
|
@ -11,8 +11,12 @@ func (c *Channel) Append(name ...string) {
|
||||||
*c = append(*c, name...)
|
*c = append(*c, name...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Channel) Format(delimiter string) string {
|
||||||
|
return strings.Join(c, delimiter)
|
||||||
|
}
|
||||||
|
|
||||||
func (c Channel) String() string {
|
func (c Channel) String() string {
|
||||||
return strings.Join(c, "/")
|
return c.Format("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if two channels are equal
|
// Check if two channels are equal
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,26 @@ func TestChannel_Is(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChannel_Format(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
c Channel
|
||||||
|
delim string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"Empty", Channel{}, ":", ""},
|
||||||
|
{"Alot#1", Channel{"one", "two", "three"}, "-", "one-two-three"},
|
||||||
|
{"Alot#2", Channel{"first", "second"}, ":", "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) {
|
func TestChannel_String(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue