From 51f7ebf3bf6a477d4b2b09c96cfc523ba22fcbfb Mon Sep 17 00:00:00 2001 From: Anton Ovchinnikov Date: Sun, 25 May 2025 19:26:30 +0200 Subject: [PATCH] test: Add cleanup target that removes dangling test containers --- Makefile | 19 +++++++++++++++++++ internal/ucind/cluster.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e51b99a3..40746260 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,26 @@ ucind-multiarch-image-push: .PHONY: test test: +ifeq ($(TEST_NAME),) go test -v ./... +else + go test -v -run ^$(TEST_NAME)$$ ./... +endif + +.PHONY: test-clean +test-clean: + @CONTAINERS=$$(docker ps --filter "name=ucind-test" -q); \ + if [ -n "$$CONTAINERS" ]; then \ + echo "Killing containers..."; \ + docker kill $$CONTAINERS; \ + fi; \ + CONTAINERS_STOPPED=$$(docker ps -a --filter "name=ucind-test" -q); \ + if [ -n "$$CONTAINERS_STOPPED" ]; then \ + echo "Removing stopped containers..."; \ + docker rm $$CONTAINERS_STOPPED; \ + else \ + echo "Nothing to clean."; \ + fi .PHONY: vet vet: diff --git a/internal/ucind/cluster.go b/internal/ucind/cluster.go index a3dcc652..1e7ed20f 100644 --- a/internal/ucind/cluster.go +++ b/internal/ucind/cluster.go @@ -72,7 +72,7 @@ func (p *Provisioner) CreateCluster(ctx context.Context, name string, opts Creat ManagedLabel: "", }, } - // Create a Docker network with the same as the cluster name. + // Create a Docker network with the same name as the cluster name. if _, err = p.dockerCli.NetworkCreate(ctx, name, netOpts); err != nil { return c, fmt.Errorf("create Docker network '%s': %w", name, err) }