github.com/cilium/cilium@v1.16.2/pkg/health/probe/responder/responder_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package responder 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestNewServersInitialization(t *testing.T) { 13 tests := []struct { 14 name string 15 address []string 16 expectedServerCount int 17 exptectedServerAddress []string 18 }{ 19 { 20 name: "Initialize http server listening on all ports", 21 address: []string{""}, 22 expectedServerCount: 1, 23 exptectedServerAddress: []string{":4240"}, 24 }, 25 { 26 name: "Initialize http server listening on ipv4 address", 27 address: []string{"192.168.1.4"}, 28 expectedServerCount: 1, 29 exptectedServerAddress: []string{"192.168.1.4:4240"}, 30 }, 31 { 32 name: "Initialize http server listening on ipv4 and ipv6 address", 33 address: []string{"192.168.1.4", "fc00:c111::2"}, 34 expectedServerCount: 2, 35 exptectedServerAddress: []string{"192.168.1.4:4240", "[fc00:c111::2]:4240"}, 36 }, 37 { 38 name: "Initialize http server with nil address", 39 address: []string{}, 40 expectedServerCount: 1, 41 exptectedServerAddress: []string{":4240"}, 42 }, 43 } 44 45 for _, tt := range tests { 46 s := NewServers(tt.address, 4240) 47 assert.NotNil(t, s) 48 assert.Equal(t, len(s.httpServers), tt.expectedServerCount, "Number of listen address doesn't match") 49 for i, s := range s.httpServers { 50 assert.Equal(t, tt.exptectedServerAddress[i], s.Addr) 51 } 52 } 53 }