@@ -18,6 +18,7 @@ package util
1818
1919import (
2020 "fmt"
21+ "io/fs"
2122 "os/user"
2223 "reflect"
2324 "sort"
@@ -308,7 +309,8 @@ var updateConfigEnvTests = []struct {
308309 {
309310 Key : "foo" ,
310311 Value : "baz" ,
311- }},
312+ },
313+ },
312314 config : & v1.Config {},
313315 replacementEnvs : []string {},
314316 expectedEnv : []string {"key=var" , "foo=baz" },
@@ -326,7 +328,8 @@ var updateConfigEnvTests = []struct {
326328 {
327329 Key : "foo" ,
328330 Value : "$argarg" ,
329- }},
331+ },
332+ },
330333 config : & v1.Config {},
331334 replacementEnvs : []string {"var=/test/with'chars'/" , "not=used" , "argarg=\" a\" b\" " },
332335 expectedEnv : []string {"key=/var/run" , "env=/test/with'chars'/" , "foo=\" a\" b\" " },
@@ -340,7 +343,8 @@ var updateConfigEnvTests = []struct {
340343 {
341344 Key : "bob" ,
342345 Value : "cool" ,
343- }},
346+ },
347+ },
344348 config : & v1.Config {Env : []string {"bob=used" , "more=test" }},
345349 replacementEnvs : []string {},
346350 expectedEnv : []string {"bob=cool" , "more=test" , "alice=nice" },
@@ -585,6 +589,43 @@ func TestGetUserGroup(t *testing.T) {
585589 }
586590}
587591
592+ func TestGetChmod (t * testing.T ) {
593+ tests := []struct {
594+ description string
595+ chmod string
596+ env []string
597+ expected fs.FileMode
598+ shdErr bool
599+ }{
600+ {
601+ description : "non empty chmod" ,
602+ chmod : "0755" ,
603+ env : []string {},
604+ expected : fs .FileMode (0o755 ),
605+ },
606+ {
607+ description : "non empty chmod with env replacement" ,
608+ chmod : "$foo" ,
609+ env : []string {"foo=0750" },
610+ expected : fs .FileMode (0o750 ),
611+ },
612+ {
613+ description : "empty chmod string" ,
614+ expected : fs .FileMode (0o600 ),
615+ },
616+ }
617+ for _ , tc := range tests {
618+ t .Run (tc .description , func (t * testing.T ) {
619+ defaultChmod := fs .FileMode (0o600 )
620+ chmod , useDefault , err := GetChmod (tc .chmod , tc .env )
621+ if useDefault {
622+ chmod = defaultChmod
623+ }
624+ testutil .CheckErrorAndDeepEqual (t , tc .shdErr , err , tc .expected , chmod )
625+ })
626+ }
627+ }
628+
588629func TestResolveEnvironmentReplacementList (t * testing.T ) {
589630 type args struct {
590631 values []string
@@ -806,7 +847,6 @@ func TestLookupUser(t *testing.T) {
806847 testutil .CheckErrorAndDeepEqual (t , tt .wantErr , err , tt .expected , got )
807848 })
808849 }
809-
810850}
811851
812852func TestIsSrcRemoteFileURL (t * testing.T ) {
0 commit comments