Skip to content

Commit 51e1e24

Browse files
authored
test(sidekick): missing tests for config package (#1595)
1 parent f193f7d commit 51e1e24

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2025 Google LLC
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+
// https://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 config
16+
17+
import (
18+
"testing"
19+
20+
"github.com/google/go-cmp/cmp"
21+
"github.com/google/go-cmp/cmp/cmpopts"
22+
)
23+
24+
func TestSourceRoots(t *testing.T) {
25+
type TestCase struct {
26+
input map[string]string
27+
want []string
28+
}
29+
testCases := []TestCase{
30+
{map[string]string{}, nil},
31+
{map[string]string{
32+
"googleapis-root": "foo",
33+
"other-root": "bar",
34+
"ignored": "baz",
35+
}, []string{"googleapis-root", "other-root"}},
36+
{map[string]string{
37+
"roots": "googleapis,more",
38+
"googleapis-root": "foo",
39+
"other-root": "bar",
40+
"more-root": "bar",
41+
"ignored": "baz",
42+
}, []string{"googleapis-root", "more-root"}},
43+
}
44+
45+
for _, c := range testCases {
46+
got := SourceRoots(c.input)
47+
less := func(a, b string) bool { return a < b }
48+
if diff := cmp.Diff(c.want, got, cmpopts.SortSlices(less)); diff != "" {
49+
t.Errorf("AllSourceRoots mismatch (-want, +got):\n%s", diff)
50+
}
51+
}
52+
}
53+
54+
func TestAllSourceRoots(t *testing.T) {
55+
type TestCase struct {
56+
input map[string]string
57+
want []string
58+
}
59+
testCases := []TestCase{
60+
{map[string]string{}, nil},
61+
{map[string]string{
62+
"googleapis-root": "foo",
63+
"other-root": "bar",
64+
"ignored": "baz",
65+
}, []string{"googleapis-root", "other-root"}},
66+
}
67+
68+
for _, c := range testCases {
69+
got := AllSourceRoots(c.input)
70+
less := func(a, b string) bool { return a < b }
71+
if diff := cmp.Diff(c.want, got, cmpopts.SortSlices(less)); diff != "" {
72+
t.Errorf("AllSourceRoots mismatch (-want, +got):\n%s", diff)
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)