vitess.io/vitess@v0.16.2/go/vt/vtgr/inst/instance_key_test.go (about) 1 /* 2 Copyright 2014 Outbrain Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 This file has been copied over from VTOrc package 19 */ 20 21 package inst 22 23 import ( 24 "testing" 25 26 "github.com/stretchr/testify/require" 27 28 "vitess.io/vitess/go/vt/vtgr/config" 29 ) 30 31 func init() { 32 config.Config.HostnameResolveMethod = "none" 33 } 34 35 var key1 = InstanceKey{Hostname: "host1", Port: 3306} 36 37 func TestInstanceKeyEquals(t *testing.T) { 38 i1 := InstanceKey{ 39 Hostname: "sql00.db", 40 Port: 3306, 41 } 42 i2 := InstanceKey{ 43 Hostname: "sql00.db", 44 Port: 3306, 45 } 46 47 require.Equal(t, i1, i2) 48 49 i2.Port = 3307 50 require.NotEqual(t, i1, i2) 51 } 52 53 func TestInstanceKeyDetach(t *testing.T) { 54 require.False(t, key1.IsDetached()) 55 detached1 := key1.DetachedKey() 56 require.True(t, detached1.IsDetached()) 57 detached2 := key1.DetachedKey() 58 require.True(t, detached2.IsDetached()) 59 require.True(t, detached1.Equals(detached2)) 60 61 reattached1 := detached1.ReattachedKey() 62 require.False(t, reattached1.IsDetached()) 63 require.True(t, reattached1.Equals(&key1)) 64 reattached2 := reattached1.ReattachedKey() 65 require.False(t, reattached2.IsDetached()) 66 require.True(t, reattached1.Equals(reattached2)) 67 }