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