Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MeNsaaH committed Jan 10, 2024
1 parent 2a18303 commit ba14d23
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ helm 3.12.2
helm-cr 1.6.1
helm-ct 3.8.0
kubeconform 0.6.3
kustomize 5.0.3
kustomize 5.1.0
tilt 0.33.2
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ build-binary:

WORKDIR /src
COPY . /src
RUN go build -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
RUN GOARM=${VARIANT#v} go build -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
SAVE ARTIFACT kubechecks

build-debug-binary:
Expand Down
2 changes: 1 addition & 1 deletion charts/kubechecks/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: kubechecks
description: A Helm chart for kubechecks
version: 0.4.1
version: 0.4.2
appVersion: "1.3.3"
type: application
maintainers:
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion cmd/controller_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func init() {
boolFlag(flags, "enable-conftest", "Set to true to enable conftest policy checking of manifests (KUBECHECKS_ENABLE_CONFTEST).")
stringFlag(flags, "label-filter", `(Optional) If set, The label that must be set on an MR (as "kubechecks:<value>") for kubechecks to process the merge request webhook (KUBECHECKS_LABEL_FILTER).`)
stringFlag(flags, "openai-api-token", "OpenAI API Token.")
stringFlag(flags, "argocd-namespace", "The namespace to watch for Application resources (KUBECHECKS_ARGOCD_NAMESPACE).", newStringOpts().withDefault("argocd"))
stringFlag(flags, "webhook-url-base", "The endpoint to listen on for incoming PR/MR event webhooks. For example, 'https://checker.mycompany.com'.")
stringFlag(flags, "webhook-url-prefix", "If your application is running behind a proxy that uses path based routing, set this value to match the path prefix. For example, '/hello/world'.")
stringFlag(flags, "webhook-secret", "Optional secret key for validating the source of incoming webhooks.")
Expand Down
Empty file.
1 change: 0 additions & 1 deletion localdev/test_apps/echo-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ spec:
helm:
valueFiles:
- values.yaml
- values-2.yaml
sources: []
project: default
syncPolicy:
Expand Down
100 changes: 0 additions & 100 deletions pkg/app_directory/app_directory.go

This file was deleted.

51 changes: 0 additions & 51 deletions pkg/app_directory/app_directory_test.go

This file was deleted.

38 changes: 29 additions & 9 deletions pkg/app_watcher/app_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app_watcher

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -37,7 +36,7 @@ func initTestObjects() *ApplicationWatcher {
},
}

appInformer, appLister := ctrl.newApplicationInformerAndLister(time.Second * 5)
appInformer, appLister := ctrl.newApplicationInformerAndLister(time.Millisecond * 500)
ctrl.appInformer = appInformer
ctrl.appLister = appLister

Expand All @@ -52,7 +51,7 @@ func TestApplicationAdded(t *testing.T) {

go ctrl.Run(ctx, 1)

time.Sleep(time.Second * 5)
time.Sleep(time.Second * 1)

assert.Equal(t, len(ctrl.cfg.VcsToArgoMap.GetMap()), 2)

Expand All @@ -66,8 +65,7 @@ func TestApplicationAdded(t *testing.T) {
t.Error(err)
}

time.Sleep(time.Second * 5)
fmt.Println(ctrl.cfg.VcsToArgoMap.GetMap())
time.Sleep(time.Second * 1)
assert.Equal(t, len(ctrl.cfg.VcsToArgoMap.GetMap()), 3)
}

Expand All @@ -79,7 +77,7 @@ func TestApplicationUpdated(t *testing.T) {

go ctrl.Run(ctx, 1)

time.Sleep(time.Second * 5)
time.Sleep(time.Second * 1)

assert.Equal(t, len(ctrl.cfg.VcsToArgoMap.GetMap()), 2)

Expand All @@ -97,7 +95,7 @@ func TestApplicationUpdated(t *testing.T) {
if err != nil {
t.Error(err)
}
time.Sleep(time.Second * 6)
time.Sleep(time.Second * 1)
oldAppDirectory = ctrl.cfg.VcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git")
newAppDirectory = ctrl.cfg.VcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo-3.git")
assert.Equal(t, oldAppDirectory.Count(), 0)
Expand All @@ -112,7 +110,7 @@ func TestApplicationDeleted(t *testing.T) {

go ctrl.Run(ctx, 1)

time.Sleep(time.Second * 5)
time.Sleep(time.Second * 1)

assert.Equal(t, len(ctrl.cfg.VcsToArgoMap.GetMap()), 2)

Expand All @@ -123,8 +121,30 @@ func TestApplicationDeleted(t *testing.T) {
if err != nil {
t.Error(err)
}
time.Sleep(time.Second * 6)
time.Sleep(time.Second * 1)

appDirectory = ctrl.cfg.VcsToArgoMap.GetAppsInRepo("https://gitlab.com/test/repo.git")
assert.Equal(t, appDirectory.Count(), 0)
}

// TestIsGitRepo will test various URLs against the isGitRepo function.
func TestIsGitRepo(t *testing.T) {
tests := []struct {
url string
expected bool
}{
{"https://github.com/user/repo.git", true},
{"https://gitlab.com/user/repo.git", true},
{"ssh://gitlab.com/user/repo.git", true},
{"[email protected]:user/repo.git", true},
{"https://bitbucket.org/user/repo.git", false},
{"[email protected]/user/repo.git", false},
{"http://myownserver.com/git/repo.git", false},
}

for _, test := range tests {
if result := isGitRepo(test.url); result != test.expected {
t.Errorf("isGitRepo(%q) = %v; want %v", test.url, result, test.expected)
}
}
}
29 changes: 29 additions & 0 deletions pkg/config/app_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"reflect"
"testing"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
Expand Down Expand Up @@ -99,3 +100,31 @@ func TestShouldInclude(t *testing.T) {
})
}
}

// TestRemoveFromSlice performs tests on the removeFromSlice function.
func TestRemoveFromSlice(t *testing.T) {
// Test for integers
ints := []int{1, 2, 3, 4, 5}
intsAfterRemoval := []int{1, 2, 4, 5}
intsTest := func(t *testing.T) {
result := removeFromSlice(ints, 3, func(a, b int) bool { return a == b })
if !reflect.DeepEqual(result, intsAfterRemoval) {
t.Errorf("Expected %v, got %v", intsAfterRemoval, result)
}
}

// Test for strings
strings := []string{"apple", "banana", "cherry", "date"}
stringsAfterRemoval := []string{"apple", "cherry", "date"}
stringsTest := func(t *testing.T) {
result := removeFromSlice(strings, "banana", func(a, b string) bool { return a == b })
if !reflect.DeepEqual(result, stringsAfterRemoval) {
t.Errorf("Expected %v, got %v", stringsAfterRemoval, result)
}
}

// Execute subtests
t.Run("Integers", intsTest)
t.Run("Strings", stringsTest)
// Add more subtests for different generic types if necessary
}
Loading

0 comments on commit ba14d23

Please sign in to comment.