MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestLoggingKeys

Function TestLoggingKeys

rest/adminapitest/admin_api_test.go:165–244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestLoggingKeys(t *testing.T) {
166 base.ResetGlobalTestLogging(t)
167 if base.GlobalTestLoggingSet.IsTrue() {
168 t.Skip("Test does not work when a global test log level is set")
169 }
170
171 // Reset logging to initial state, in case any other tests forgot to clean up after themselves
172 base.SetUpTestLogging(t, base.LevelInfo, base.KeyNone)
173
174 rt := rest.NewRestTester(t, nil)
175 defer rt.Close()
176
177 // Assert default log channels are enabled
178 response := rt.SendAdminRequest("GET", "/_logging", "")
179 var logKeys map[string]interface{}
180 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &logKeys))
181 assert.Equal(t, map[string]interface{}{}, logKeys)
182
183 // Set logKeys, Changes+ should enable Changes (PUT replaces any existing log keys)
184 rest.RequireStatus(t, rt.SendAdminRequest("PUT", "/_logging", `{"Changes+":true, "Cache":true, "HTTP":true}`), 200)
185
186 response = rt.SendAdminRequest("GET", "/_logging", "")
187 var updatedLogKeys map[string]interface{}
188 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &updatedLogKeys))
189 assert.Equal(t, map[string]interface{}{"Changes": true, "Cache": true, "HTTP": true}, updatedLogKeys)
190
191 // Disable Changes logKey which should also disable Changes+
192 rest.RequireStatus(t, rt.SendAdminRequest("POST", "/_logging", `{"Changes":false}`), 200)
193
194 response = rt.SendAdminRequest("GET", "/_logging", "")
195 var deletedLogKeys map[string]interface{}
196 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &deletedLogKeys))
197 assert.Equal(t, map[string]interface{}{"Cache": true, "HTTP": true}, deletedLogKeys)
198
199 // Enable Changes++, which should enable Changes (POST append logKeys)
200 rest.RequireStatus(t, rt.SendAdminRequest("POST", "/_logging", `{"Changes++":true}`), 200)
201
202 response = rt.SendAdminRequest("GET", "/_logging", "")
203 var appendedLogKeys map[string]interface{}
204 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &appendedLogKeys))
205 assert.Equal(t, map[string]interface{}{"Changes": true, "Cache": true, "HTTP": true}, appendedLogKeys)
206
207 // Disable Changes++ (POST modifies logKeys)
208 rest.RequireStatus(t, rt.SendAdminRequest("POST", "/_logging", `{"Changes++":false}`), 200)
209
210 response = rt.SendAdminRequest("GET", "/_logging", "")
211 var disabledLogKeys map[string]interface{}
212 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &disabledLogKeys))
213 assert.Equal(t, map[string]interface{}{"Cache": true, "HTTP": true}, disabledLogKeys)
214
215 // Re-Enable Changes++, which should enable Changes (POST append logKeys)
216 rest.RequireStatus(t, rt.SendAdminRequest("POST", "/_logging", `{"Changes++":true}`), 200)
217
218 // Disable Changes+ which should disable Changes (POST modifies logKeys)
219 rest.RequireStatus(t, rt.SendAdminRequest("POST", "/_logging", `{"Changes+":false}`), 200)
220
221 response = rt.SendAdminRequest("GET", "/_logging", "")
222 var disabled2LogKeys map[string]interface{}

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
ResetGlobalTestLoggingFunction · 0.92
SetUpTestLoggingFunction · 0.92
NewRestTesterFunction · 0.92
JSONUnmarshalFunction · 0.92
RequireStatusFunction · 0.92
IsTrueMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected