1 // Copyright 2015 The etcd 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 v2store 16 17 import "testing" 18 19 // TestIsHidden tests isHidden functions. 20 func TestIsHidden(t *testing.T) { 21 // watch at "/" 22 // key is "/_foo", hidden to "/" 23 // expected: hidden = true 24 watch := "/" 25 key := "/_foo" 26 hidden := isHidden(watch, key) 27 if !hidden { 28 t.Fatalf("%v should be hidden to %v\n", key, watch) 29 } 30 31 // watch at "/_foo" 32 // key is "/_foo", not hidden to "/_foo" 33 // expected: hidden = false 34 watch = "/_foo" 35 hidden = isHidden(watch, key) 36 if hidden { 37 t.Fatalf("%v should not be hidden to %v\n", key, watch) 38 } 39 40 // watch at "/_foo/" 41 // key is "/_foo/foo", not hidden to "/_foo" 42 key = "/_foo/foo" 43 hidden = isHidden(watch, key) 44 if hidden { 45 t.Fatalf("%v should not be hidden to %v\n", key, watch) 46 } 47 48 // watch at "/_foo/" 49 // key is "/_foo/_foo", hidden to "/_foo" 50 key = "/_foo/_foo" 51 hidden = isHidden(watch, key) 52 if !hidden { 53 t.Fatalf("%v should be hidden to %v\n", key, watch) 54 } 55 56 // watch at "/_foo/foo" 57 // key is "/_foo" 58 watch = "_foo/foo" 59 key = "/_foo/" 60 hidden = isHidden(watch, key) 61 if hidden { 62 t.Fatalf("%v should not be hidden to %v\n", key, watch) 63 } 64 } 65