Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating test instructions in TESTING.md #155

Merged
merged 9 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
go-version: ^1.22
- run: cd repctl && make test
- name: Run unit tests and check package coverage
run: make gen-coverage
run: make unit-test
go_security_scan:
permissions: write-all
name: Go security - Main Folder
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ KUSTOMIZE ?= $(GOBIN)/kustomize

IMG ?= "NOIMG"

#Generate semver.mk
#Generate semver.mk for setting the semantic version
gen-semver:
(cd core; rm -f core_generated.go; go generate)
go run core/semver/semver.go -f mk > semver.mk

# Run tests
# Run all _test.go files (including those in repctl/) in this repo and generate coverage report
test: generate fmt vet static-crd gen-semver
go test ./... -coverprofile cover.out

Expand Down Expand Up @@ -155,6 +155,7 @@ image-migrator-dev: build-sidecar-migrator

image-node-rescanner-dev: build-sidecar-node-rescanner
make -f image.mk sidecar-node-rescanner-dev

#To start mock-grpc server
start-server-win:
go run test/mock-server/main.go --csi-address localhost:4772 --stubs test/mock-server/stubs
Expand All @@ -170,21 +171,19 @@ run-fake-e2e-test:
go test test/e2e-framework/fake_integration_test.go -v

# To run e2e tests for controller
# Set the kubernetes config file path to REMOTE_KUBE_CONFIG_PATH environment variable
# Example: export REMOTE_KUBE_CONFIG_PATH=C:\config-files\remote-cluster-config.yaml
run-controller-tests:
go test test/e2e-framework/controller_integration_test.go -v

#To generate coverage for the csi-replicator
gen-coverage-csi-replicator:
# Execute unit tests for the csi-replicator controller and generate coverage report
unit-test-csi-replicator:
go test ./controllers/csi-replicator/ ./pkg/connection/ -v -race -coverpkg=./controllers/csi-replicator/ -coverprofile cover.out

#To generate coverage for the replication-controller
gen-coverage-replication-controller:
# Execute unit tests for the replication-controller and generate coverage report
unit-test-replication-controller:
go test ./controllers/replication-controller/ -v -race -coverpkg=./controllers/replication-controller/ -coverprofile cover.out

#To generate coverage for all the controllers
gen-coverage:
# Execute unit tests for all the controllers and generate coverage report
unit-test:
( cd controllers; go clean -cache; go test -race -v -cover ./... -coverprofile cover.out )

## Tool Versions
Expand All @@ -208,6 +207,7 @@ else
CONTROLLER_GEN=$(shell which controller-gen)
endif

# find or download kustomize
kustomize:
ifeq (, $(shell which kustomize))
@{ \
Expand Down
48 changes: 37 additions & 11 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@
# Testing
There are many unit tests written in the respective packages in `_test.go` files, Along with the unit tests there are integration tests written separately for both Sidecar and Replication controller. These integration tests cover complete end to end scenario testing starting from automated way of creating the resources PVC, PV and RG and by running the sidecar/replication controllers internally from the tests itself.
There are many unit tests written in the respective packages in `_test.go` files. Along with the unit tests there are integration tests written separately for both Sidecar and Replication controller. These integration tests cover complete end to end scenario testing starting from automated way of creating the resources PVC, PV and RG and by running the sidecar/replication controllers internally from the tests itself.

## Integration Tests
The integration test cases can be executed by using the `Makefile` recipe or from any IDE directly. These tests can be ran against any driver without any modification to the code by just updating the driver and the storage class to use in the stubs and in the integration tests config variable.

```
suite.driver = common.Driver{
DriverName: "csi-unity.dellemc.com",
StorageClass: "replication-unity",
DriverName: "csi-powerstore.dellemc.com",
StorageClass: "replication-powerstore",
}
```

### Sidecar
To run sidecar integration tests:
- Start the mock gRPC server based on the dev environment operating system and wait for the server to start.

```bash
make run-sidecar-tests
```
For Linux distros:
```bash
make start-server-unix
```

For Windows:

```bash
make start-server-win
```

- Open a new terminal window and run the tests.

```bash
make run-sidecar-tests
```

### Replication Controller Manager
To run replication controller tests:

Set the remote cluster config file path into the environment variable and run the tests.
Set `REMOTE_KUBE_CONFIG_PATH` to the path to the remote cluster's kubeconfig and run the tests.

```bash
export REMOTE_KUBE_CONFIG_PATH=C:\config-files\remote-cluster-config.yaml
export REMOTE_KUBE_CONFIG_PATH=$HOME/.kube/config-remote
make run-controller-tests
```

To run unit tests:
## Unit Tests
To run unit tests for CSM Replication:

```bash
make unit-test
```

### Repctl
To run unit test for repctl:

```bash
make gen-coverage
cd ./repctl
make test
```
2 changes: 1 addition & 1 deletion test/e2e-framework/sidecar/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
export CSI_SOCK_DIR="/var/run/csi"
export CSI_SOCK_FILE="csi.sock"
export CSI_ADDRESS=$CSI_SOCK_DIR/$CSI_SOCK_FILE
export KUBECONFIG_PATH="/root/.kube/config"
export KUBECONFIG_PATH=$HOME/.kube/config

export PROBE_TIMEOUT="10s"
export TIMEOUT="180s"
Expand Down
2 changes: 1 addition & 1 deletion test/mock-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
)

func init() {
flag.StringVar(&csiAddress, "csi-address", "/var/run/csi.sock", "Address of the grpc server")
flag.StringVar(&csiAddress, "csi-address", "/var/run/csi/csi.sock", "Address of the grpc server")
flag.StringVar(&stubs, "stubs", "./stubs", "Location of the stubs directory")
flag.StringVar(&apiPort, "apiPort", "4771", "API port")
flag.Parse()
Expand Down
Loading