1 package api
2
3 import (
4 "testing"
5
6 "github.com/google/go-cmp/cmp"
7 )
8
9 func TestMergeRunningModes(t *testing.T) {
10 type args struct {
11 m map[string]RunningModes
12 }
13 tests := []struct {
14 name string
15 args args
16 want RunningModes
17 }{
18 {
19 name: "nil map",
20 want: nil,
21 },
22 {
23 name: "all false with some unknown modes",
24 args: args{
25 m: map[string]RunningModes{
26 "podman": map[RunningMode]bool{
27 RunningModeDev: false,
28 RunningModeDeploy: false,
29 },
30 "cluster": map[RunningMode]bool{
31 RunningModeDev: false,
32 RunningModeDeploy: false,
33 },
34 "unknown-platform": map[RunningMode]bool{
35 "unknown-mode": true,
36 "another-mode": true,
37 },
38 },
39 },
40 want: NewRunningModes(),
41 },
42 {
43 name: "true for one platform and false for another",
44 args: args{
45 m: map[string]RunningModes{
46 "podman": map[RunningMode]bool{
47 RunningModeDev: true,
48 RunningModeDeploy: false,
49 },
50 "cluster": map[RunningMode]bool{
51 RunningModeDev: false,
52 RunningModeDeploy: true,
53 },
54 },
55 },
56 want: map[RunningMode]bool{
57 RunningModeDev: true,
58 RunningModeDeploy: true,
59 },
60 },
61 {
62 name: "true for all platforms",
63 args: args{
64 m: map[string]RunningModes{
65 "podman": map[RunningMode]bool{
66 RunningModeDev: true,
67 RunningModeDeploy: true,
68 },
69 "cluster": map[RunningMode]bool{
70 RunningModeDev: true,
71 RunningModeDeploy: true,
72 },
73 },
74 },
75 want: map[RunningMode]bool{
76 RunningModeDev: true,
77 RunningModeDeploy: true,
78 },
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 got := MergeRunningModes(tt.args.m)
84 if diff := cmp.Diff(tt.want, got); diff != "" {
85 t.Errorf("MergeRunningModes() mismatch (-want +got):\n%s", diff)
86 }
87 })
88 }
89 }
90
View as plain text