github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/opts/secret_test.go (about) 1 package opts 2 3 import ( 4 "os" 5 "testing" 6 7 "gotest.tools/v3/assert" 8 is "gotest.tools/v3/assert/cmp" 9 ) 10 11 func TestSecretOptions(t *testing.T) { 12 testCases := []struct { 13 name string 14 input string 15 secretName string 16 fileName string 17 uid string 18 gid string 19 fileMode uint 20 }{ 21 { 22 name: "Simple", 23 input: "app-secret", 24 secretName: "app-secret", 25 fileName: "app-secret", 26 uid: "0", 27 gid: "0", 28 }, 29 { 30 name: "Source", 31 input: "source=foo", 32 secretName: "foo", 33 fileName: "foo", 34 }, 35 { 36 name: "SourceTarget", 37 input: "source=foo,target=testing", 38 secretName: "foo", 39 fileName: "testing", 40 }, 41 { 42 name: "Shorthand", 43 input: "src=foo,target=testing", 44 secretName: "foo", 45 fileName: "testing", 46 }, 47 { 48 name: "CustomUidGid", 49 input: "source=foo,target=testing,uid=1000,gid=1001", 50 secretName: "foo", 51 fileName: "testing", 52 uid: "1000", 53 gid: "1001", 54 }, 55 { 56 name: "CustomMode", 57 input: "source=foo,target=testing,uid=1000,gid=1001,mode=0444", 58 secretName: "foo", 59 fileName: "testing", 60 uid: "1000", 61 gid: "1001", 62 fileMode: 0444, 63 }, 64 } 65 66 for _, tc := range testCases { 67 tc := tc 68 t.Run(tc.name, func(t *testing.T) { 69 var opt SecretOpt 70 assert.NilError(t, opt.Set(tc.input)) 71 reqs := opt.Value() 72 assert.Assert(t, is.Len(reqs, 1)) 73 req := reqs[0] 74 assert.Check(t, is.Equal(tc.secretName, req.SecretName)) 75 assert.Check(t, is.Equal(tc.fileName, req.File.Name)) 76 if tc.uid != "" { 77 assert.Check(t, is.Equal(tc.uid, req.File.UID)) 78 } 79 if tc.gid != "" { 80 assert.Check(t, is.Equal(tc.gid, req.File.GID)) 81 } 82 if tc.fileMode != 0 { 83 assert.Check(t, is.Equal(os.FileMode(tc.fileMode), req.File.Mode)) 84 } 85 }) 86 } 87 }