Debian Codegraph @

pkg/authentication/authenticator/audiences_test.go

raw
1 /*
2 Copyright 2018 The Kubernetes Authors.
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 package authenticator
18
19 import (
20 "reflect"
21 "testing"
22 )
23
24 func TestIntersect(t *testing.T) {
25 cs := []struct {
26 auds, tauds Audiences
27 expected Audiences
28 }{
29 {
30 auds: nil,
31 tauds: nil,
32 expected: Audiences{},
33 },
34 {
35 auds: nil,
36 tauds: Audiences{"foo"},
37 expected: Audiences{},
38 },
39 {
40 auds: Audiences{},
41 tauds: Audiences{},
42 expected: Audiences{},
43 },
44 {
45 auds: Audiences{"foo"},
46 tauds: Audiences{},
47 expected: Audiences{},
48 },
49 {
50 auds: Audiences{"foo"},
51 tauds: Audiences{"foo"},
52 expected: Audiences{"foo"},
53 },
54 {
55 auds: Audiences{"foo", "bar"},
56 tauds: Audiences{"foo", "bar"},
57 expected: Audiences{"foo", "bar"},
58 },
59 {
60 auds: Audiences{"foo", "bar"},
61 tauds: Audiences{"foo", "wat"},
62 expected: Audiences{"foo"},
63 },
64 {
65 auds: Audiences{"foo", "bar"},
66 tauds: Audiences{"pls", "wat"},
67 expected: Audiences{},
68 },
69 }
70 for _, c := range cs {
71 t.Run("auds", func(t *testing.T) {
72 if got, want := c.auds.Intersect(c.tauds), c.expected; !reflect.DeepEqual(got, want) {
73 t.Errorf("unexpected intersection.\ngot:\t%v\nwant:\t%v", got, want)
74 }
75 })
76 }
77 }