55 "encoding/base64"
66 "io"
77 "maps"
8+ "os"
89 "testing"
910 "time"
1011
@@ -13,13 +14,86 @@ import (
1314 "github.com/stretchr/testify/require"
1415)
1516
17+ func TestReadRequestValuesFile (t * testing.T ) {
18+ tests := []struct {
19+ name string
20+ fileContent []byte
21+ expErr bool
22+ errMsg string
23+ }{
24+ {
25+ name : "success" ,
26+ fileContent : []byte ("{\" jsonKey\" :\" jsonValue\" }" ),
27+ },
28+ {
29+ name : "No JSON content" ,
30+ fileContent : []byte ("not json" ),
31+ expErr : true ,
32+ errMsg : "unable to parse JSON from request's values file" ,
33+ },
34+ }
35+
36+ for _ , tc := range tests {
37+ tt := tc
38+ t .Run (tt .name , func (t * testing.T ) {
39+ t .Parallel ()
40+
41+ inputMap := map [string ]string {
42+ "testKey" : "testValue" ,
43+ }
44+
45+ tmpDir := t .TempDir ()
46+ tempFile , err := createTmpFileWithContent (
47+ tmpDir ,
48+ "fileReadTest.txt" ,
49+ tt .fileContent ,
50+ )
51+
52+ require .NoError (t , err )
53+
54+ outputMap , err := ReadRequestValuesFile (
55+ tempFile ,
56+ inputMap ,
57+ )
58+
59+ if tt .expErr {
60+ require .ErrorContains (t , err , tt .errMsg )
61+ return
62+ }
63+
64+ require .NoError (t , err )
65+ require .Equal (t , "jsonValue" , outputMap ["jsonKey" ])
66+ require .Equal (t , "testValue" , outputMap ["testKey" ])
67+
68+ t .Cleanup (func () { os .RemoveAll (tmpDir ) })
69+ })
70+ }
71+
72+ t .Run ("fileNotExist" , func (t * testing.T ) {
73+ t .Parallel ()
74+
75+ inputMap := map [string ]string {
76+ "testKey" : "testValue" ,
77+ }
78+
79+ _ , err := ReadRequestValuesFile (
80+ "fileNotExist" ,
81+ inputMap ,
82+ )
83+
84+ require .ErrorContains (t , err , "no such file or directory" )
85+ })
86+ }
87+
1688func TestParseRequestJSONValues (t * testing.T ) {
17- inputMap := make (map [string ]string )
18- inputMap ["testKey" ] = "testValue"
89+ inputMap := map [string ]string {
90+ "testKey" : "testValue" ,
91+ }
1992
20- mapToValidJSON := make (map [string ]string )
21- mapToValidJSON ["testKey2" ] = "testValue2"
22- mapToValidJSON ["testKey3" ] = "testValue3"
93+ mapToValidJSON := map [string ]string {
94+ "testKey2" : "testValue2" ,
95+ "testKey3" : "testValue3" ,
96+ }
2397
2498 tests := []struct {
2599 name string
0 commit comments