MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestMapBoolValueAsOpt

Function TestMapBoolValueAsOpt

pkg/maputil/maputil_test.go:26–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestMapBoolValueAsOpt(t *testing.T) {
27 tests := []struct {
28 m map[string]string
29 key string
30 want bool
31 wantErr bool
32 }{
33 // cases that key does not exist
34 {
35 m: map[string]string{},
36 key: "key",
37 want: false,
38 wantErr: false,
39 },
40 // key exist, but has no value
41 {
42 m: map[string]string{"key": ""},
43 key: "key",
44 want: true,
45 wantErr: false,
46 },
47 // key exist, and set to true
48 {
49 m: map[string]string{"key": "true"},
50 key: "key",
51 want: true,
52 wantErr: false,
53 },
54 // key exist, and set to false
55 {
56 m: map[string]string{"key": "false"},
57 key: "key",
58 want: false,
59 wantErr: false,
60 },
61 // cases with error
62 {
63 m: map[string]string{"key": "abc"},
64 key: "key",
65 want: false,
66 wantErr: true,
67 },
68 }
69
70 for i, tt := range tests {
71 got, err := MapBoolValueAsOpt(tt.m, tt.key)
72 assert.Equal(t, got, tt.want, fmt.Sprintf("case %d", (i+1)))
73 if (err != nil) != tt.wantErr {
74 t.Errorf("MapBoolValueAsOpt() case %d error = %v, wantErr %v", (i + 1), err, tt.wantErr)
75 }
76 }
77}

Callers

nothing calls this directly

Calls 1

MapBoolValueAsOptFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…