Skip to content

Commit 312a4a8

Browse files
committed
fix lints
1 parent b1adda5 commit 312a4a8

File tree

3 files changed

+16
-45
lines changed

3 files changed

+16
-45
lines changed

internal/assigner/assigner.go

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ func StartAssigner(server string, port int, token string, interval time.Duration
4040
ticker := time.NewTicker(interval)
4141
defer ticker.Stop()
4242

43-
for {
44-
select {
45-
case <-ticker.C:
46-
AssignTasks(server, port, token)
47-
}
43+
for range ticker.C {
44+
AssignTasks(server, port, token)
4845
}
46+
4947
}
5048

5149
func AssignTasks(server string, port int, token string) {
@@ -167,11 +165,7 @@ func isScanAssigned(server string, port int, token string, scanID uuid.UUID) boo
167165
}
168166
defer resp.Body.Close()
169167

170-
if resp.StatusCode == http.StatusOK {
171-
return true
172-
}
173-
174-
return false
168+
return resp.StatusCode == http.StatusOK
175169
}
176170

177171
func createAgentTask(server string, port int, token string, agentID int, scanID uuid.UUID) error {
@@ -206,31 +200,3 @@ func createAgentTask(server string, port int, token string, agentID int, scanID
206200

207201
return nil
208202
}
209-
210-
//func updateAgentStatus(server, token string, agentID int, status string) error {
211-
// reqBody := agents.UpdateAgentRequest{
212-
// Status: &status,
213-
// }
214-
//
215-
// reqBodyJSON, _ := json.Marshal(reqBody)
216-
//
217-
// req, err := http.NewRequest("PUT", fmt.Sprintf("%s/api/v1/agents/%d", server, agentID), bytes.NewBuffer(reqBodyJSON))
218-
// if err != nil {
219-
// return err
220-
// }
221-
//
222-
// req.Header.Set("Authorization", "Bearer "+token)
223-
// req.Header.Set("Content-Type", "application/json")
224-
//
225-
// resp, err := http.DefaultClient.Do(req)
226-
// if err != nil {
227-
// return err
228-
// }
229-
// defer resp.Body.Close()
230-
//
231-
// if resp.StatusCode != http.StatusOK {
232-
// return fmt.Errorf("server responded with status: %d", resp.StatusCode)
233-
// }
234-
//
235-
// return nil
236-
//}

internal/assigner/assigner_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ func TestAssignTasks(t *testing.T) {
4040
scanHandler := func(w http.ResponseWriter, r *http.Request) {
4141
if r.URL.Path == "/api/v1/scans" && r.URL.Query().Get("status") == "scan_pending" {
4242
w.WriteHeader(http.StatusOK)
43-
json.NewEncoder(w).Encode(mockScans)
43+
if err := json.NewEncoder(w).Encode(mockScans); err != nil {
44+
http.Error(w, "Failed to encode mock scans", http.StatusInternalServerError)
45+
return
46+
}
4447
} else if r.URL.Path == "/api/v1/agents" && r.URL.Query().Get("status") == "connected" {
4548
w.WriteHeader(http.StatusOK)
46-
json.NewEncoder(w).Encode(mockAgents)
49+
if err := json.NewEncoder(w).Encode(mockAgents); err != nil {
50+
http.Error(w, "Failed to encode mock agents", http.StatusInternalServerError)
51+
return
52+
}
4753
} else if r.URL.Path == "/api/v1/agents/tasks" {
4854
w.WriteHeader(http.StatusOK)
4955
} else {
@@ -68,7 +74,10 @@ func TestAssignTasksWithNoAgents(t *testing.T) {
6874
scanHandler := func(w http.ResponseWriter, r *http.Request) {
6975
if r.URL.Path == "/api/v1/scans" && r.URL.Query().Get("status") == "scan_pending" {
7076
w.WriteHeader(http.StatusOK)
71-
json.NewEncoder(w).Encode(mockScans)
77+
if err := json.NewEncoder(w).Encode(mockScans); err != nil {
78+
http.Error(w, "Failed to encode mock scans", http.StatusInternalServerError)
79+
return
80+
}
7281
} else if r.URL.Path == "/api/v1/agents" {
7382
w.WriteHeader(http.StatusOK)
7483
json.NewEncoder(w).Encode([]MockAgent{}) // No agents available

internal/restapi/v1/agenttasks/get_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,3 @@ func TestListAgentTasks_OrderedByCreatedAt(t *testing.T) {
173173
assert.Equal(t, task1.ID, res[0].ID) // Oldest task first
174174
assert.Equal(t, task2.ID, res[1].ID) // Newest task last
175175
}
176-
177-
func uuidPtr(u uuid.UUID) *uuid.UUID {
178-
return &u
179-
}

0 commit comments

Comments
 (0)