File: secret_test.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (87 lines) | stat: -rw-r--r-- 1,865 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package opts

import (
	"os"
	"testing"

	"gotest.tools/v3/assert"
	is "gotest.tools/v3/assert/cmp"
)

func TestSecretOptions(t *testing.T) {
	testCases := []struct {
		name       string
		input      string
		secretName string
		fileName   string
		uid        string
		gid        string
		fileMode   uint
	}{
		{
			name:       "Simple",
			input:      "app-secret",
			secretName: "app-secret",
			fileName:   "app-secret",
			uid:        "0",
			gid:        "0",
		},
		{
			name:       "Source",
			input:      "source=foo",
			secretName: "foo",
			fileName:   "foo",
		},
		{
			name:       "SourceTarget",
			input:      "source=foo,target=testing",
			secretName: "foo",
			fileName:   "testing",
		},
		{
			name:       "Shorthand",
			input:      "src=foo,target=testing",
			secretName: "foo",
			fileName:   "testing",
		},
		{
			name:       "CustomUidGid",
			input:      "source=foo,target=testing,uid=1000,gid=1001",
			secretName: "foo",
			fileName:   "testing",
			uid:        "1000",
			gid:        "1001",
		},
		{
			name:       "CustomMode",
			input:      "source=foo,target=testing,uid=1000,gid=1001,mode=0444",
			secretName: "foo",
			fileName:   "testing",
			uid:        "1000",
			gid:        "1001",
			fileMode:   0444,
		},
	}

	for _, tc := range testCases {
		tc := tc
		t.Run(tc.name, func(t *testing.T) {
			var opt SecretOpt
			assert.NilError(t, opt.Set(tc.input))
			reqs := opt.Value()
			assert.Assert(t, is.Len(reqs, 1))
			req := reqs[0]
			assert.Check(t, is.Equal(tc.secretName, req.SecretName))
			assert.Check(t, is.Equal(tc.fileName, req.File.Name))
			if tc.uid != "" {
				assert.Check(t, is.Equal(tc.uid, req.File.UID))
			}
			if tc.gid != "" {
				assert.Check(t, is.Equal(tc.gid, req.File.GID))
			}
			if tc.fileMode != 0 {
				assert.Check(t, is.Equal(os.FileMode(tc.fileMode), req.File.Mode))
			}
		})
	}
}