github.com/uber/kraken@v0.1.4/lib/persistedretry/tagreplication/remotes_test.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 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 package tagreplication 15 16 import ( 17 "testing" 18 19 "github.com/stretchr/testify/require" 20 ) 21 22 func TestRemotesMatch(t *testing.T) { 23 require := require.New(t) 24 25 remotes, err := RemotesConfig{ 26 "a": []string{"foo/.*", "bar/.*"}, 27 "b": []string{"foo/.*"}, 28 }.Build() 29 require.NoError(err) 30 31 for tag, expected := range map[string][]string{ 32 "foo/123": {"a", "b"}, 33 "bar/abc": {"a"}, 34 "baz/456": nil, 35 "xxx": nil, 36 } { 37 require.ElementsMatch(expected, remotes.Match(tag), "Tag: %s", tag) 38 } 39 } 40 41 func TestRemotesValid(t *testing.T) { 42 require := require.New(t) 43 44 remotes, err := RemotesConfig{ 45 "a": []string{"foo/.*"}, 46 "b": []string{"foo/.*"}, 47 "c": []string{"foo/.*"}, 48 "d": []string{"bar/.*"}, 49 }.Build() 50 require.NoError(err) 51 52 tests := []struct { 53 tag string 54 addr string 55 expected bool 56 }{ 57 {"foo/123", "a", true}, 58 {"foo/123", "b", true}, 59 {"foo/123", "c", true}, 60 {"foo/123", "d", false}, 61 {"bar/123", "d", true}, 62 {"bar/123", "c", false}, 63 {"bar/123", "x", false}, 64 } 65 for _, test := range tests { 66 require.Equal( 67 test.expected, remotes.Valid(test.tag, test.addr), 68 "Tag: %s, Addr: %s", test.tag, test.addr) 69 } 70 }