github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/registry/cache/util_test.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/util/registry/util_test.go 14 15 package cache 16 17 import ( 18 "os" 19 "testing" 20 21 "github.com/tickoalcantara12/micro/v3/service/registry" 22 ) 23 24 func TestRemove(t *testing.T) { 25 services := []*registry.Service{ 26 { 27 Name: "foo", 28 Version: "1.0.0", 29 Nodes: []*registry.Node{ 30 { 31 Id: "foo-123", 32 Address: "localhost:9999", 33 }, 34 }, 35 }, 36 { 37 Name: "foo", 38 Version: "1.0.0", 39 Nodes: []*registry.Node{ 40 { 41 Id: "foo-123", 42 Address: "localhost:6666", 43 }, 44 }, 45 }, 46 } 47 48 servs := Remove([]*registry.Service{services[0]}, []*registry.Service{services[1]}) 49 if i := len(servs); i > 0 { 50 t.Errorf("Expected 0 nodes, got %d: %+v", i, servs) 51 } 52 if len(os.Getenv("IN_TRAVIS_CI")) == 0 { 53 t.Logf("Services %+v", servs) 54 } 55 } 56 57 func TestRemoveNodes(t *testing.T) { 58 services := []*registry.Service{ 59 { 60 Name: "foo", 61 Version: "1.0.0", 62 Nodes: []*registry.Node{ 63 { 64 Id: "foo-123", 65 Address: "localhost:9999", 66 }, 67 { 68 Id: "foo-321", 69 Address: "localhost:6666", 70 }, 71 }, 72 }, 73 { 74 Name: "foo", 75 Version: "1.0.0", 76 Nodes: []*registry.Node{ 77 { 78 Id: "foo-123", 79 Address: "localhost:6666", 80 }, 81 }, 82 }, 83 } 84 85 nodes := delNodes(services[0].Nodes, services[1].Nodes) 86 if i := len(nodes); i != 1 { 87 t.Errorf("Expected only 1 node, got %d: %+v", i, nodes) 88 } 89 if len(os.Getenv("IN_TRAVIS_CI")) == 0 { 90 t.Logf("Nodes %+v", nodes) 91 } 92 }