Skip to content

Commit

Permalink
🧪 test(csc): Add csc tests (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Mriyam Tamuli <mbtamuli@gmail.com>
  • Loading branch information
mbtamuli authored Dec 27, 2023
1 parent 6497b01 commit 93ea24e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 25 deletions.
2 changes: 2 additions & 0 deletions emptyDirClone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
test.sock
52 changes: 42 additions & 10 deletions emptyDirClone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
.PHONY: all
all: help

GIT_HASH=$(shell git describe --always --long)
GIT_TAG=$(shell git name-rev --name-only --tags HEAD | sed 's/^undefined$$//')
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GIT_INFO=$(if $(GIT_TAG),$(GIT_TAG),$(GIT_BRANCH)-$(GIT_HASH))

SHELL=/bin/bash

# Binary PATH
BINARY := bin/emptydirclone
# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/mbtamuli/csi-quickstart/emptydirclone
# Image tag
Expand Down Expand Up @@ -52,12 +50,36 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: fmt vet ## Run tests.
.PHONY: csc-test
csc-test: fmt vet build ## Run `csc` tests.
@./tests/csc_tests.sh $(BINARY)

.PHONY: e2e
e2e: fmt vet ## Run e2e tests.
go test ./tests/e2e -v


STERN_EXISTS := $(shell stern --version 2>/dev/null)
.PHONY: logs
logs:
ifdef STERN_EXISTS
stern --namespace emptydirclone \
--selector 'app=emptydirclone-plugin' \
--container '(csi-volume-driver|node-driver-registrar)'
else
kubectl logs --namespace emptydirclone \
--selector 'app=emptydirclone-plugin' \
--container csi-volume-driver \
--container node-driver-registrar \
--follow --ignore-errors --prefix
endif

##@ Build

.PHONY: build
build: ## Build binary for testing with `csc`
go build -ldflags "-s -w -X main.version=${VERSION}" -o $(BINARY) main.go

.PHONY: docker-build
docker-build: ## Build docker image with the plugin.
docker build --build-arg VERSION=${VERSION} --tag ${IMG}:${TAG} .
Expand All @@ -68,11 +90,12 @@ docker-push: ## Push docker image with the plugin.
docker push ${IMG}:${TAG}
docker push ${IMG}:debug

CLUSTER_CONTEXT=$(shell kubectl config current-context)
KIND_CLUSTER_NAME=$(CLUSTER_CONTEXT:kind-%=%)
.PHONY: kind-load
kind-load: ## Load docker image with the plugin, into Kind cluster targeted by the current context(`kubectl config current-context`).
$(eval NAME = $(shell kubectl config current-context | sed 's/kind-//'))
kind load docker-image ${IMG}:${TAG} --name $(NAME)
kind load docker-image ${IMG}:debug --name $(NAME)
kind load docker-image ${IMG}:${TAG} --name $(KIND_CLUSTER_NAME)
kind load docker-image ${IMG}:debug --name $(KIND_CLUSTER_NAME)

##@ Deploy

Expand All @@ -84,3 +107,12 @@ deploy: ## Deploy the plugin to the K8s cluster specified in $KUBECONFIG.
.PHONY: undeploy
undeploy: ## Undeploy the plugin from the K8s cluster specified in $KUBECONFIG.
kubectl delete --file deploy

## Helpers

# Get information from git to reliably identify
# the commit from a branch/tag to set the version
GIT_HASH=$(shell git describe --always --long)
GIT_TAG=$(shell git name-rev --name-only --tags HEAD | sed 's/^undefined$$//')
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GIT_INFO=$(if $(GIT_TAG),$(GIT_TAG),$(GIT_BRANCH)-$(GIT_HASH))
38 changes: 23 additions & 15 deletions emptyDirClone/docs/running-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

- [Docker](https://docs.docker.com/engine/install/) | For macOS or Windows install [Docker Desktop](https://docs.docker.com/desktop/)
- [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)

- \(Optional\) [stern](https://github.com/stern/stern#installation)

## Quickstart

Expand All @@ -16,16 +19,13 @@ make deploy

## Developing Locally

Helpful [`Make`][1] targets are added to allow doing common operational tasks. Run `make help` to see all options.
[`Make`][1] targets are added to allow doing common operational tasks. Run `make help` to see all options.

### Setup cluster

1. Once the pre-requisites are met, you can create the local Kubernetes cluster using
```sh
make cluster-up

# Or manually
kind create cluster
```

1. Using any of these methods, once the cluster is created, verify the cluster is running using
Expand All @@ -44,18 +44,8 @@ Helpful [`Make`][1] targets are added to allow doing common operational tasks. R
To delete the local cluster, run
```sh
make cluster-down
# Or manually
kind delete cluster
```

### Running tests

Run the tests using
```sh
go test -v ./tests/e2e
```

### Build and Deploy

1. To build the image
Expand Down Expand Up @@ -83,8 +73,26 @@ go test -v ./tests/e2e
```

1. To deploy the manifests
```
```sh
make deploy
```

### Running tests and checking logs

1. Check plugin logs. Run the following in a separate terminal as it will "follow" the logs
```sh
make logs
```

1. Run [`csc`](https://github.com/rexray/gocsi/tree/master/csc) tests
```sh
make csc-tests
```


1. Run the e2e tests using. See [`e2e`](../tests/e2e/)
```sh
make e2e
```

[1]: https://www.gnu.org/software/make/
21 changes: 21 additions & 0 deletions emptyDirClone/tests/csc_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes

socket_path="unix://$PWD/test.sock"
plugin="${1:-emptydirclone} --endpoint $socket_path"
csc="${2:-csc} --endpoint $socket_path"

printf '\nRunning csc tests\n'

printf '\nRunning the CSI plugin in background\n'
$plugin > /dev/null 2>&1 &
sleep 2

printf '\nIdentity service\n'
printf '\n==> csc identity plugin-info\n'
$csc identity plugin-info

kill %1

0 comments on commit 93ea24e

Please sign in to comment.