Skip to content

Commit

Permalink
add kind for e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
elsesiy committed Aug 12, 2024
1 parent d28660c commit 66c3f24
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ jobs:
ci_job:
name: test
runs-on: ubuntu-22.04
container:
image: golang:1.22
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create kind cluster
uses: helm/kind-action@v1
with:
cluster_name: kvs-test
install_only: true
- name: Prepare env
run: make bootstrap
- name: Test
run: make test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ BINARY := kubectl-view-secret

build: kubectl-view-secret

bootstrap:
./hack/kind-bootstrap.sh

test: $(SOURCES)
go test -v -short -race -timeout 30s ./...

clean:
@rm -rf $(BINARY)
@kind delete cluster --name kvs-test

$(BINARY): $(SOURCES)
CGO_ENABLED=0 go build -o $(BINARY) -ldflags="-s -w" ./cmd/$(BINARY).go
42 changes: 42 additions & 0 deletions hack/kind-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -euo pipefail

CLUSTER_NAME="kvs-test"

# Check if kind & kubectl are installed
which kind &>/dev/null || { echo "failed to find 'kind' binary, please install it" && exit 1; }
which kubectl &>/dev/null || { echo "failed to find 'kubectl' binary, please install it" && exit 1; }

# Ensure the cluster exists
[[ $(kind get clusters) == *$CLUSTER_NAME* ]] || kind create cluster --name $CLUSTER_NAME

# Set context in case there are mulitple
kubectl config set-context kind-${CLUSTER_NAME}

# Seed test secrets

## secret 'test' in namespace 'default' (multiple keys)
kubectl apply -f - <<EOF
apiVersion: v1
data:
key1: dmFsdWUxCg==
key2: dmFsdWUyCg==
kind: Secret
metadata:
name: test
namespace: default
type: Opaque
EOF

## secret 'test2' in namespace 'default' (single key)
kubectl apply -f - <<EOF
apiVersion: v1
data:
key1: dmFsdWUx
kind: Secret
metadata:
name: test2
namespace: default
type: Opaque
EOF
1 change: 1 addition & 0 deletions pkg/cmd/view-secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestNewCmdViewSecret(t *testing.T) {
"custom ns": {args: []string{"test", "--namespace", "bob"}},
"impersonate group": {args: []string{"test", "--as-group", "golovers"}},
"impersonate user": {args: []string{"test", "--as", "gopher"}},
"invalid arg count": {args: []string{"a", "b", "c"}, wantErr: errors.New("accepts between 0 and 2 arg(s), received 3")},
"quiet": {args: []string{"test", "--all", "--quiet"}},
"unknown flag": {args: []string{"--version"}, wantErr: errors.New("unknown flag: --version")},
}
Expand Down

0 comments on commit 66c3f24

Please sign in to comment.