Skip to content

Commit ec544da

Browse files
gofmt -w
1 parent 1ab3241 commit ec544da

File tree

11 files changed

+267
-267
lines changed

11 files changed

+267
-267
lines changed

pkg/backup/external_simple.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func (e *BackupExecutor) countRecordsInFile(filePath string) (int, float64, erro
474474
const maxCapacity = 1024 * 1024 // 1MB
475475
buf := make([]byte, maxCapacity)
476476
scanner.Buffer(buf, maxCapacity)
477-
477+
478478
count := 0
479479

480480
for scanner.Scan() {
@@ -496,7 +496,7 @@ func (e *BackupExecutor) countRecordsInFile(filePath string) (int, float64, erro
496496
func (e *BackupExecutor) maskSensitiveArgs(args []string) string {
497497
maskedArgs := make([]string, len(args))
498498
copy(maskedArgs, args)
499-
499+
500500
for i, arg := range maskedArgs {
501501
if arg == "--uri" && i+1 < len(maskedArgs) {
502502
// Mask credentials in URI
@@ -507,11 +507,11 @@ func (e *BackupExecutor) maskSensitiveArgs(args []string) string {
507507
if len(parts) == 2 {
508508
protocolPart := parts[0] + "://"
509509
remaining := parts[1]
510-
510+
511511
if atIndex := strings.Index(remaining, "@"); atIndex != -1 {
512512
hostPart := remaining[atIndex:]
513513
credPart := remaining[:atIndex]
514-
514+
515515
// Check if there are credentials
516516
if strings.Contains(credPart, ":") {
517517
maskedArgs[i+1] = protocolPart + "***:***" + hostPart
@@ -521,7 +521,7 @@ func (e *BackupExecutor) maskSensitiveArgs(args []string) string {
521521
}
522522
}
523523
}
524-
524+
525525
return strings.Join(maskedArgs, " ")
526526
}
527527

pkg/syncer/mongodb/mongodb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,11 @@ func (s *MongoDBSyncer) convertRawBSONToWriteModel(rawData bson.Raw, sourceDB, c
11631163
// Check if delete operations should be ignored for this collection
11641164
advancedSettings := s.findTableAdvancedSettings(collectionName)
11651165
if advancedSettings.IgnoreDeleteOps {
1166-
s.logger.Debugf("[MongoDB] Ignoring delete operation for %s.%s (ignoreDeleteOps=true)",
1166+
s.logger.Debugf("[MongoDB] Ignoring delete operation for %s.%s (ignoreDeleteOps=true)",
11671167
sourceDB, collectionName)
11681168
return nil
11691169
}
1170-
1170+
11711171
var docID interface{}
11721172
if dk, ok := event["documentKey"].(bson.M); ok {
11731173
docID = dk["_id"]
@@ -2026,11 +2026,11 @@ func (s *MongoDBSyncer) deserializeWriteModel(data json.RawMessage, collectionNa
20262026
// Check if delete operations should be ignored for this collection
20272027
advancedSettings := s.findTableAdvancedSettings(collectionName)
20282028
if advancedSettings.IgnoreDeleteOps {
2029-
s.logger.Debugf("[MongoDB] Ignoring delete operation during retry for %s (ignoreDeleteOps=true)",
2029+
s.logger.Debugf("[MongoDB] Ignoring delete operation during retry for %s (ignoreDeleteOps=true)",
20302030
collectionName)
20312031
return nil, nil
20322032
}
2033-
2033+
20342034
filter, ok := modelData["filter"]
20352035
if !ok {
20362036
return nil, fmt.Errorf("missing filter for delete operation")

pkg/syncer/test/api_coverage_test.go

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,65 @@ func TestAPICoverage(t *testing.T) {
1818
// Test backup list handler
1919
req := httptest.NewRequest("GET", "/api/backup", nil)
2020
w := httptest.NewRecorder()
21-
21+
2222
api.BackupListHandler(w, req)
23-
23+
2424
if w.Code == 0 {
2525
t.Error("Expected response code to be set")
2626
}
2727
t.Logf("BackupListHandler returned status: %d", w.Code)
28-
28+
2929
// Test backup create handler with invalid JSON
3030
invalidJSON := `{"invalid": json}`
3131
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString(invalidJSON))
3232
req.Header.Set("Content-Type", "application/json")
3333
w = httptest.NewRecorder()
34-
34+
3535
api.BackupCreateHandler(w, req)
3636
t.Logf("BackupCreateHandler with invalid JSON returned status: %d", w.Code)
37-
37+
3838
// Test backup create handler with valid JSON but missing fields
3939
validJSONMissingFields := `{"name": "test"}`
4040
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString(validJSONMissingFields))
4141
req.Header.Set("Content-Type", "application/json")
4242
w = httptest.NewRecorder()
43-
43+
4444
api.BackupCreateHandler(w, req)
4545
t.Logf("BackupCreateHandler with missing fields returned status: %d", w.Code)
46-
46+
4747
// Test backup update handler
4848
req = httptest.NewRequest("PUT", "/api/backup/1", bytes.NewBufferString(`{"enable": true}`))
4949
req.Header.Set("Content-Type", "application/json")
5050
w = httptest.NewRecorder()
51-
51+
5252
api.BackupUpdateHandler(w, req)
5353
t.Logf("BackupUpdateHandler returned status: %d", w.Code)
54-
54+
5555
// Test backup delete handler
5656
req = httptest.NewRequest("DELETE", "/api/backup/1", nil)
5757
w = httptest.NewRecorder()
58-
58+
5959
api.BackupDeleteHandler(w, req)
6060
t.Logf("BackupDeleteHandler returned status: %d", w.Code)
61-
61+
6262
// Test backup pause handler
6363
req = httptest.NewRequest("PUT", "/api/backup/1/pause", nil)
6464
w = httptest.NewRecorder()
65-
65+
6666
api.BackupPauseHandler(w, req)
6767
t.Logf("BackupPauseHandler returned status: %d", w.Code)
68-
68+
6969
// Test backup resume handler
7070
req = httptest.NewRequest("PUT", "/api/backup/1/resume", nil)
7171
w = httptest.NewRecorder()
72-
72+
7373
api.BackupResumeHandler(w, req)
7474
t.Logf("BackupResumeHandler returned status: %d", w.Code)
75-
75+
7676
// Test backup run handler
7777
req = httptest.NewRequest("POST", "/api/backup/1/run", nil)
7878
w = httptest.NewRecorder()
79-
79+
8080
api.BackupRunHandler(w, req)
8181
t.Logf("BackupRunHandler returned status: %d", w.Code)
8282

@@ -88,7 +88,7 @@ func TestAPICoverage(t *testing.T) {
8888
// For now, just test that the API package is accessible
8989
req := httptest.NewRequest("GET", "/api/backup", nil)
9090
w := httptest.NewRecorder()
91-
91+
9292
api.BackupListHandler(w, req)
9393
t.Logf("Additional API test returned status: %d", w.Code)
9494

@@ -97,27 +97,27 @@ func TestAPICoverage(t *testing.T) {
9797

9898
t.Run("APIErrorHandling", func(t *testing.T) {
9999
// Test various error conditions
100-
100+
101101
// Test with unsupported method
102102
req := httptest.NewRequest("PATCH", "/api/backup", nil)
103103
w := httptest.NewRecorder()
104-
104+
105105
api.BackupListHandler(w, req)
106106
t.Logf("BackupListHandler with PATCH method returned status: %d", w.Code)
107-
107+
108108
// Test with malformed request body
109109
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString("{"))
110110
req.Header.Set("Content-Type", "application/json")
111111
w = httptest.NewRecorder()
112-
112+
113113
api.BackupCreateHandler(w, req)
114114
t.Logf("BackupCreateHandler with malformed JSON returned status: %d", w.Code)
115-
115+
116116
// Test with empty body
117117
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString(""))
118118
req.Header.Set("Content-Type", "application/json")
119119
w = httptest.NewRecorder()
120-
120+
121121
api.BackupCreateHandler(w, req)
122122
t.Logf("BackupCreateHandler with empty body returned status: %d", w.Code)
123123

@@ -126,18 +126,18 @@ func TestAPICoverage(t *testing.T) {
126126

127127
t.Run("HTTPMethodValidation", func(t *testing.T) {
128128
// Test all handlers with incorrect HTTP methods
129-
129+
130130
handlers := map[string]func(http.ResponseWriter, *http.Request){
131131
"GET /api/backup (POST)": api.BackupListHandler,
132-
"POST /api/backup (GET)": api.BackupCreateHandler,
132+
"POST /api/backup (GET)": api.BackupCreateHandler,
133133
"PUT /api/backup/1 (GET)": api.BackupUpdateHandler,
134134
"DELETE /api/backup/1 (GET)": api.BackupDeleteHandler,
135135
}
136-
136+
137137
for testName, handler := range handlers {
138138
req := httptest.NewRequest("GET", "/api/backup", nil)
139139
w := httptest.NewRecorder()
140-
140+
141141
handler(w, req)
142142
t.Logf("%s returned status: %d", testName, w.Code)
143143
}
@@ -147,19 +147,19 @@ func TestAPICoverage(t *testing.T) {
147147

148148
t.Run("RequestValidation", func(t *testing.T) {
149149
// Test request validation with various content types
150-
150+
151151
// Test with wrong content type
152152
req := httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString(`{"test": "data"}`))
153153
req.Header.Set("Content-Type", "text/plain")
154154
w := httptest.NewRecorder()
155-
155+
156156
api.BackupCreateHandler(w, req)
157157
t.Logf("BackupCreateHandler with text/plain returned status: %d", w.Code)
158-
158+
159159
// Test with missing content type
160160
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBufferString(`{"test": "data"}`))
161161
w = httptest.NewRecorder()
162-
162+
163163
api.BackupCreateHandler(w, req)
164164
t.Logf("BackupCreateHandler with no content type returned status: %d", w.Code)
165165

@@ -174,13 +174,13 @@ func TestAPIResponseHandling(t *testing.T) {
174174
req := httptest.NewRequest("GET", "/api/backup", nil)
175175
req.Header.Set("Accept", "application/json")
176176
w := httptest.NewRecorder()
177-
177+
178178
api.BackupListHandler(w, req)
179-
179+
180180
// Check if response has proper content type
181181
contentType := w.Header().Get("Content-Type")
182182
t.Logf("BackupListHandler content type: %s", contentType)
183-
183+
184184
// Try to parse response as JSON
185185
if w.Body.Len() > 0 {
186186
var response interface{}
@@ -198,30 +198,30 @@ func TestAPIResponseHandling(t *testing.T) {
198198
t.Run("ErrorResponses", func(t *testing.T) {
199199
// Test error response handling
200200
invalidRequests := []struct {
201-
method string
202-
path string
203-
body string
201+
method string
202+
path string
203+
body string
204204
contentType string
205205
}{
206206
{"POST", "/api/backup", `{"incomplete"}`, "application/json"},
207207
{"PUT", "/api/backup/invalid_id", `{"enable": true}`, "application/json"},
208208
{"DELETE", "/api/backup/999999", "", ""},
209209
}
210-
210+
211211
for _, req := range invalidRequests {
212212
httpReq := httptest.NewRequest(req.method, req.path, bytes.NewBufferString(req.body))
213213
if req.contentType != "" {
214214
httpReq.Header.Set("Content-Type", req.contentType)
215215
}
216216
w := httptest.NewRecorder()
217-
217+
218218
// Route to appropriate handler based on path
219219
if req.path == "/api/backup" && req.method == "POST" {
220220
api.BackupCreateHandler(w, httpReq)
221221
} else {
222222
api.BackupListHandler(w, httpReq) // Default handler for testing
223223
}
224-
224+
225225
t.Logf("%s %s returned status: %d", req.method, req.path, w.Code)
226226
}
227227

@@ -233,14 +233,14 @@ func TestAPIResponseHandling(t *testing.T) {
233233
func TestAPIIntegrationScenarios(t *testing.T) {
234234
t.Run("BackupWorkflow", func(t *testing.T) {
235235
// Simulate a complete backup workflow
236-
236+
237237
// 1. List existing backups
238238
req := httptest.NewRequest("GET", "/api/backup", nil)
239239
w := httptest.NewRecorder()
240240
api.BackupListHandler(w, req)
241241
initialStatus := w.Code
242242
t.Logf("1. List backups: %d", initialStatus)
243-
243+
244244
// 2. Try to create a backup
245245
createReq := map[string]interface{}{
246246
"name": "test-backup",
@@ -251,21 +251,21 @@ func TestAPIIntegrationScenarios(t *testing.T) {
251251
},
252252
}
253253
createJSON, _ := json.Marshal(createReq)
254-
254+
255255
req = httptest.NewRequest("POST", "/api/backup", bytes.NewBuffer(createJSON))
256256
req.Header.Set("Content-Type", "application/json")
257257
w = httptest.NewRecorder()
258258
api.BackupCreateHandler(w, req)
259259
createStatus := w.Code
260260
t.Logf("2. Create backup: %d", createStatus)
261-
261+
262262
// 3. Try to run the backup
263263
req = httptest.NewRequest("POST", "/api/backup/1/run", nil)
264264
w = httptest.NewRecorder()
265265
api.BackupRunHandler(w, req)
266266
runStatus := w.Code
267267
t.Logf("3. Run backup: %d", runStatus)
268-
268+
269269
// 4. Try to pause the backup
270270
req = httptest.NewRequest("PUT", "/api/backup/1/pause", nil)
271271
w = httptest.NewRecorder()
@@ -275,15 +275,15 @@ func TestAPIIntegrationScenarios(t *testing.T) {
275275

276276
t.Log("Backup workflow test completed")
277277
})
278-
278+
279279
t.Run("ConcurrentRequests", func(t *testing.T) {
280280
// Test handling of concurrent requests
281281
ctx, cancel := context.WithCancel(context.Background())
282282
defer cancel()
283-
283+
284284
var wg sync.WaitGroup
285285
results := make(chan int, 5)
286-
286+
287287
// Launch multiple concurrent requests
288288
for i := 0; i < 5; i++ {
289289
wg.Add(1)
@@ -300,20 +300,20 @@ func TestAPIIntegrationScenarios(t *testing.T) {
300300
}
301301
}(i)
302302
}
303-
303+
304304
// Wait for all goroutines to complete
305305
go func() {
306306
wg.Wait()
307307
close(results)
308308
}()
309-
309+
310310
// Collect results safely in the main test goroutine
311311
requestCount := 0
312312
for code := range results {
313313
t.Logf("Concurrent request %d returned status: %d", requestCount, code)
314314
requestCount++
315315
}
316-
316+
317317
t.Log("Concurrent requests test completed")
318318
})
319-
}
319+
}

0 commit comments

Comments
 (0)