istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/serviceregistry/mock/discovery_test.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mock 16 17 import ( 18 "testing" 19 ) 20 21 func TestMakeIP(t *testing.T) { 22 HelloService := MakeService(ServiceArgs{ 23 Hostname: "hello.default.svc.cluster.local", 24 Address: "10.1.0.0", 25 ServiceAccounts: []string{}, 26 ClusterID: "cluster-1", 27 }) 28 HelloInstanceV0 := MakeIP(HelloService, 0) 29 30 if HelloInstanceV0 != "10.1.1.0" { 31 t.Fatalf("MakeIP() can not handle ip4 address.") 32 } 33 34 HelloService1 := MakeService(ServiceArgs{ 35 Hostname: "hello.default.svc.cluster.local", 36 Address: "asa", 37 ServiceAccounts: []string{}, 38 ClusterID: "cluster-1", 39 }) 40 HelloInstanceV1 := MakeIP(HelloService1, 0) 41 if HelloInstanceV1 != "" { 42 t.Fatalf("MakeIP() can not handle string not the ip address.") 43 } 44 45 HelloService2 := MakeService(ServiceArgs{ 46 Hostname: "hello.default.svc.cluster.local", 47 Address: "0:0:0:0:0:ffff:192.1.56.10", 48 ServiceAccounts: []string{}, 49 ClusterID: "cluster-1", 50 }) 51 HelloInstanceV2 := MakeIP(HelloService2, 0) 52 if HelloInstanceV2 != "192.1.1.0" { 53 t.Fatalf("MakeIP() can not handle ip6 address.") 54 } 55 }