Skip to content

Commit

Permalink
feat: add xdiscovery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalvas committed Aug 28, 2023
1 parent 7f772e3 commit f642450
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions xdiscovery/tools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package xdiscovery

import "testing"

func TestSrvJoinHostPort(t *testing.T) {
testCases := []struct {
name string
input []SrvDiscoveredHost
expected []string
}{
{
name: "EmptyInput",
input: []SrvDiscoveredHost{},
expected: []string{},
},
{
name: "SingleHost",
input: []SrvDiscoveredHost{
{Target: "localhost", Port: 8080},
},
expected: []string{"localhost:8080"},
},
{
name: "MultipleHosts",
input: []SrvDiscoveredHost{
{Target: "host1", Port: 80},
{Target: "host2", Port: 443},
},
expected: []string{"host1:80", "host2:443"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := SrvJoinHostPort(tc.input)
if len(result) != len(tc.expected) {
t.Errorf("Expected %d hosts, but got %d", len(tc.expected), len(result))
}

for i := 0; i < len(result); i++ {
if result[i] != tc.expected[i] {
t.Errorf("Expected host %s, but got %s", tc.expected[i], result[i])
}
}
})
}
}

0 comments on commit f642450

Please sign in to comment.