File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,10 @@ func (s *Sdk) GetConfig(key string) (string, error) {
88
88
return "" , err
89
89
}
90
90
91
+ if daemonValue == nil {
92
+ return "" , nil
93
+ }
94
+
91
95
stringValue , ok := daemonValue .(string )
92
96
if ! ok {
93
97
return "" , fmt .Errorf ("Received non-string JSON %v" , daemonValue )
Original file line number Diff line number Diff line change @@ -111,6 +111,42 @@ func TestGetConfig(t *testing.T) {
111
111
}
112
112
}
113
113
114
+ func TestGetConfig_Null (t * testing.T ) {
115
+ expectedResponse := `{"value": null}`
116
+ expectedBody := map [string ]interface {}{
117
+ "key" : "test-key" ,
118
+ }
119
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
120
+ ValidateRequest (t , r , "/config/get" )
121
+
122
+ var tmp map [string ]interface {}
123
+ err := json .NewDecoder (r .Body ).Decode (& tmp )
124
+ if err != nil {
125
+ t .Errorf ("Error in decoding response body: %s" , err )
126
+ }
127
+
128
+ if ! reflect .DeepEqual (tmp , expectedBody ) {
129
+ t .Errorf ("Error unexpected request body: %+v" , tmp )
130
+ }
131
+
132
+ fmt .Fprintf (w , expectedResponse )
133
+ }))
134
+
135
+ defer ts .Close ()
136
+
137
+ SetPortVar (t , ts )
138
+
139
+ s := NewSdk ()
140
+ output , err := s .GetConfig ("test-key" )
141
+ if err != nil {
142
+ t .Errorf ("Error in config request: %v" , err )
143
+ }
144
+
145
+ if output != "" {
146
+ t .Errorf ("Error unexpected output: %v" , output )
147
+ }
148
+ }
149
+
114
150
func TestSetConfig (t * testing.T ) {
115
151
expectedBody := map [string ]interface {}{
116
152
"key" : "key-of-value" ,
You can’t perform that action at this time.
0 commit comments