feature: handle delete operation for IPs
This commit is contained in:
1 parent
4f597505cc
commit
f8336740ad
20 files changed
+1083
-5
No files matched your search
@@ -105,6 +105,76 @@ func TestIPCancel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPDelete(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
fake.ips = []ipQueueItem{{IPAddress: "7.7.7.7", State: "checking", UpdatedAt: now, CreatedAt: now}}
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := postForm(t, ts, "DELETE", "/ips/7.7.7.7", nil)
|
||||
if strings.Contains(body, "7.7.7.7") {
|
||||
t.Fatalf("expected 7.7.7.7 removed from table, got:\n%s", body)
|
||||
}
|
||||
if len(fake.ips) != 0 {
|
||||
t.Fatalf("expected fake control-api queue empty, got %+v", fake.ips)
|
||||
}
|
||||
|
||||
// Deleting an already-gone address is a 404, surfaced via banner.
|
||||
body = postForm(t, ts, "DELETE", "/ips/7.7.7.7", nil)
|
||||
if !strings.Contains(body, "error-banner") {
|
||||
t.Fatalf("expected error banner deleting unknown ip, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsDeleteSelected(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
fake.ips = []ipQueueItem{
|
||||
{IPAddress: "1.1.1.1", State: "queued", UpdatedAt: now, CreatedAt: now},
|
||||
{IPAddress: "2.2.2.2", State: "queued", UpdatedAt: now, CreatedAt: now},
|
||||
{IPAddress: "3.3.3.3", State: "queued", UpdatedAt: now, CreatedAt: now},
|
||||
}
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := postForm(t, ts, "POST", "/ips/delete", map[string][]string{"addresses": {"1.1.1.1", "2.2.2.2"}})
|
||||
if strings.Contains(body, "1.1.1.1") || strings.Contains(body, "2.2.2.2") {
|
||||
t.Fatalf("expected selected addresses removed, got:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, "3.3.3.3") {
|
||||
t.Fatalf("expected untouched address still listed, got:\n%s", body)
|
||||
}
|
||||
if len(fake.ips) != 1 || fake.ips[0].IPAddress != "3.3.3.3" {
|
||||
t.Fatalf("expected only 3.3.3.3 left in fake control-api, got %+v", fake.ips)
|
||||
}
|
||||
|
||||
// Empty selection is a client error banner, not a 500.
|
||||
body = postForm(t, ts, "POST", "/ips/delete", nil)
|
||||
if !strings.Contains(body, "alert-warning") {
|
||||
t.Fatalf("expected client error banner for empty selection, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsClear(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
fake.ips = []ipQueueItem{
|
||||
{IPAddress: "1.1.1.1", State: "checking", UpdatedAt: now, CreatedAt: now},
|
||||
{IPAddress: "2.2.2.2", State: "queued", UpdatedAt: now, CreatedAt: now},
|
||||
}
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := postForm(t, ts, "POST", "/ips/clear", nil)
|
||||
if strings.Contains(body, "1.1.1.1") || strings.Contains(body, "2.2.2.2") {
|
||||
t.Fatalf("expected all addresses removed, got:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, "Очередь пуста") {
|
||||
t.Fatalf("expected empty-queue message, got:\n%s", body)
|
||||
}
|
||||
if len(fake.ips) != 0 {
|
||||
t.Fatalf("expected fake control-api queue empty, got %+v", fake.ips)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorsCRUD(t *testing.T) {
|
||||
_, caURL := newFakeControlAPI(t)
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
Reference in new issue
Block a user