...
1 package unpack
2
3 import (
4 "testing"
5
6 "edge-infra.dev/pkg/f8n/warehouse/oci/layer"
7 )
8
9 func TestOptions(t *testing.T) {
10 tcs := map[string]struct {
11 input []Option
12 valid bool
13 }{
14 "WithInfraNamespace without infra layer": {
15 []Option{WithInfraNamespace("foo")},
16 false,
17 },
18 "WithInfraNamespace and ForLayerKeys": {
19 []Option{WithInfraNamespace("foo"), ForLayerKeys(layer.Infra.String())},
20 true,
21 },
22 "WithInfraNamespace and ForLayerTypes": {
23 []Option{WithInfraNamespace("foo"), ForLayerTypes(layer.Infra)},
24 true,
25 },
26 "ForLayerKeys and ForLayerTypes are mutually exclusive": {
27 []Option{ForLayerKeys("prometheus", "runtime"), ForLayerTypes("runtime")},
28 false,
29 },
30 }
31
32 for name, tc := range tcs {
33 t.Run(name, func(t *testing.T) {
34 _, err := makeOptions(tc.input...)
35
36 switch {
37 case tc.valid && err != nil:
38 t.Error("unexpected error", err)
39 case !tc.valid && err == nil:
40 t.Error("expected an error")
41 }
42 })
43 }
44 }
45
View as plain text