Skip to content

Commit

Permalink
run go vet (#70)
Browse files Browse the repository at this point in the history
* run go vet
explcit conflict with kind test
* run tests one at a time

Signed-off-by: Manabu Mccloskey <[email protected]>
  • Loading branch information
nabuskey authored Oct 27, 2023
1 parent 6b32abf commit 92be6f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ vet: ## Run go vet against code.
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
ifeq ($(RUN),)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test --tags=integration ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -p 1 --tags=integration ./... -coverprofile cover.out
else
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test --tags=integration ./... -coverprofile cover.out -run $(RUN)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -p 1--tags=integration ./... -coverprofile cover.out -run $(RUN)
endif


Expand All @@ -54,4 +54,4 @@ $(CONTROLLER_GEN): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
45 changes: 23 additions & 22 deletions pkg/controllers/gitserver/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package gitserver
import (
"context"
"fmt"
"github.com/cnoe-io/idpbuilder/pkg/kind"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"io"
"net"
"os"
"strconv"
"strings"
"testing"
"time"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/cnoe-io/idpbuilder/pkg/apps"
"github.com/cnoe-io/idpbuilder/pkg/docker"
"github.com/cnoe-io/idpbuilder/pkg/kind"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/go-connections/nat"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
controllerruntime "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -60,22 +59,6 @@ func TestReconcileGitServerImage(t *testing.T) {
t.Fatalf("failed pulilng registry image: %v", err)
}

waitTimeout := time.Second * 90
waitInterval := time.Second * 3
// very crude. no guarantee that the port will be available by the time request is sent to docker
endTime := time.Now().Add(waitTimeout)
for {
if time.Now().After(endTime) {
t.Fatalf("Timed out waiting for port %d to be available", kind.ExposedRegistryPort)
}
conn, cErr := net.DialTimeout("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(int(kind.ExposedRegistryPort))), time.Second*3)
if cErr != nil {
break
}
conn.Close()
time.Sleep(waitInterval)
}

resp, err := dockerClient.ContainerCreate(ctx, &container.Config{
Image: "docker.io/library/registry:2",
Tty: false,
Expand All @@ -98,6 +81,25 @@ func TestReconcileGitServerImage(t *testing.T) {

defer dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})

waitTimeout := time.Second * 90
waitInterval := time.Second * 3
endTime := time.Now().Add(waitTimeout)
// avoid failures with the container that uses port 5001 in TestReconcileRegistry
for {
if time.Now().After(endTime) {
t.Fatalf("Timed out waiting for idpbuilder-testcase-registry container to terminate")
}
containers, _ := dockerClient.ContainerList(ctx, types.ContainerListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{
Key: "name",
Value: "idpbuilder-testcase-registry",
}),
})
if len(containers) == 0 {
break
}
time.Sleep(waitInterval)
}
err = dockerClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
if err != nil {
t.Fatalf("failed starting container %v", err)
Expand All @@ -117,4 +119,3 @@ func TestReconcileGitServerImage(t *testing.T) {
t.Errorf("Removing docker image: %v", err)
}
}

1 change: 0 additions & 1 deletion pkg/kind/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ func TestReconcileRegistry(t *testing.T) {
t.Fatalf("Error reconciling registry: %v", err)
}
}

0 comments on commit 92be6f9

Please sign in to comment.