Skip to content

Commit ad823c7

Browse files
author
Amit Kumar Das
authored
chore(testing): update readme w.r.t programmatic vs declarative testing (#188)
This commit makes changes to clearly indicate programmatic as well declarative way to test D-operators' Kubernetes controllers. It is important to note that the same model can be followed by other Operators repo if needed. This model has worked fine so far. It makes use of GitHub VM as launching machine & same VM used as a single node K3s cluster to run the tests (both declarative as well as programmatic). Signed-off-by: AmitKumarDas <[email protected]>
1 parent 5fc998d commit ad823c7

21 files changed

+51
-30
lines changed

.github/workflows/test-release.yaml

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
---
2-
name: Unit Test, E to E Test and Github Release (if on master)
2+
name: Testing and Github Release (if on master)
33
on: [push, pull_request]
44
jobs:
55
unittest:
66
runs-on: ubuntu-18.04
7-
strategy:
8-
matrix:
9-
test: ['test']
10-
name: ${{ matrix.test }}
7+
name: Unit Test
118
steps:
129
- name: Checkout Code
1310
uses: actions/checkout@v2
1411
- name: Setup Golang
1512
uses: actions/setup-go@v2
1613
with:
1714
go-version: 1.13.5
18-
- run: make ${{ matrix.test }}
15+
- run: make test
1916
integrationtest:
2017
runs-on: ubuntu-18.04
21-
name: integrationtest
18+
name: Integration Test
2219
steps:
2320
- name: Checkout Code
2421
uses: actions/checkout@v2
@@ -27,24 +24,21 @@ jobs:
2724
with:
2825
go-version: 1.13.5
2926
- run: sudo make integration-test-suite
30-
e2etest:
27+
declarativetest:
3128
runs-on: ubuntu-18.04
32-
strategy:
33-
matrix:
34-
test: ['e2e-test']
35-
name: ${{ matrix.test }}
29+
name: Declarative Test
3630
steps:
3731
- name: Checkout Code
3832
uses: actions/checkout@v2
3933
- name: Setup Golang
4034
uses: actions/setup-go@v2
4135
with:
4236
go-version: 1.13.5
43-
- run: sudo make ${{ matrix.test }}
37+
- run: sudo make declarative-test-suite
4438
release:
4539
name: Make Github Release
4640
runs-on: ubuntu-18.04
47-
needs: ['unittest', 'e2etest', 'integrationtest']
41+
needs: ['unittest', 'declarativetest', 'integrationtest']
4842
steps:
4943
- name: Checkout Code
5044
uses: actions/checkout@v1

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tools/d-action/vendor/
33
d-operators
44
test/bin/
55
test/kubebin/
6-
test/e2e/uninstall-k3s.txt
6+
test/declarative/uninstall-k3s.txt
77
test/integration/uninstall-k3s.txt
88
uninstall-k3s.txt
99
dope

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ integration-test:
4040
# @go test ./... -cover --tags=integration -v -args --logtostderr -v=1
4141
@go test ./... -cover --tags=integration
4242

43-
.PHONY: e2e-test
44-
e2e-test:
45-
@cd test/e2e && ./suite.sh
43+
.PHONY: declarative-test-suite
44+
declarative-test-suite:
45+
@cd test/declarative && ./suite.sh
4646

4747
.PHONY: integration-test-suite
4848
integration-test-suite:

README.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,40 @@ It is important to understand that these declarative patterns are built upon pro
5454
### When to use D-operators
5555
D-operators is not meant to build complex controller logic like Deployment, StatefulSet or Pod in a declarative yaml. However, if one needs to use available Kubernetes resources to build new k8s controller(s) then d-operators should be considered to build one. D-operators helps implement the last mile automation needed to manage applications & infrastructure in Kubernetes clusters.
5656
57-
### E to E testing
57+
### Declarative Testing
5858
D-operators make use of its custom resource(s) to test its controllers. One can imagine these custom resources acting as the building blocks to implement a custom CI framework. One of the primary advantages with this approach, is to let custom resources remove the need to write code to implement test cases.
5959
60-
_NOTE: One can make use of these YAMLs (kind: Recipe) to test their own Kubernetes controllers declaratively_
60+
_NOTE: One can make use of these YAMLs (kind: Recipe) to test any Kubernetes controllers declaratively_
6161
62-
Navigate to test/experiments to learn more on these YAMLs.
62+
Navigate to test/declarative/experiments to learn more on these YAMLs.
6363
6464
```sh
65-
# Following runs the e2e test suite
65+
# Following runs the declarative test suite
6666
#
67-
# NOTE: test/e2e/suite.sh does the following:
67+
# NOTE: test/declarative/suite.sh does the following:
6868
# - d-operators' image known as 'dope' is built
6969
# - a docker container is started & acts as the image registry
7070
# - dope image is pushed to this image registry
7171
# - k3s is installed with above image registry
7272
# - d-operators' manifests are applied
7373
# - experiments _(i.e. test code written as YAMLs)_ are applied
7474
# - experiments are asserted
75-
# - if all experiments pass then e2e is a success else it failed
75+
# - if all experiments pass then this testing is a success else it failed
7676
# - k3s is un-installed
7777
# - local image registry is stopped
78-
sudo make e2e-test
78+
sudo make declarative-test-suite
7979
```
8080

81-
### Deploying experiments using D-operators
82-
To deploy experiments using d-operators apply the below commands:
83-
- kubectl apply -f deploy/
84-
- kubectl apply -f test/experiments/<experiment-yaml>
81+
### Programmatic Testing
82+
D-operators also lets one to write testing Kubernetes controllers using Golang. This involves building the docker image (refer Dockerfile.testing) of the entire codebase and letting it run as a Kubernetes pod (refer test/integration/it.yaml). The setup required run these tests can be found at test/integration folder. Actual test logic are regular _test.go files found in respective packages. These _test.go files need to be tagged appropriately. These mode of testing has the additional advantage of getting the code coverage.
83+
84+
```go
85+
// +build integration
86+
```
87+
88+
```sh
89+
make integration-test-suite
90+
```
8591

8692
### Available Kubernetes controllers
8793
- [x] kind: Recipe

pkg/recipe/list_int_items_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func TestListItemsRun(t *testing.T) {
5252
"metadata": map[string]interface{}{
5353
"name": "cm-one",
5454
"namespace": "list-items-integration-testing",
55+
"labels": map[string]interface{}{
56+
"ns": "list-items-integration-testing",
57+
},
5558
},
5659
},
5760
},
@@ -67,6 +70,9 @@ func TestListItemsRun(t *testing.T) {
6770
"metadata": map[string]interface{}{
6871
"name": "cm-two",
6972
"namespace": "list-items-integration-testing",
73+
"labels": map[string]interface{}{
74+
"ns": "list-items-integration-testing",
75+
},
7076
},
7177
},
7278
},
@@ -81,6 +87,9 @@ func TestListItemsRun(t *testing.T) {
8187
"kind": "ConfigMap",
8288
"metadata": map[string]interface{}{
8389
"namespace": "list-items-integration-testing",
90+
"labels": map[string]interface{}{
91+
"ns": "list-items-integration-testing",
92+
},
8493
},
8594
},
8695
},
@@ -135,6 +144,9 @@ func TestListItemsRun(t *testing.T) {
135144
"kind": "ConfigMap",
136145
"metadata": map[string]interface{}{
137146
"namespace": "list-items-integration-testing",
147+
"labels": map[string]interface{}{
148+
"ns": "list-items-integration-testing",
149+
},
138150
},
139151
},
140152
},

pkg/recipe/recipe_int_list_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func TestListSimpleRun(t *testing.T) {
5252
"metadata": map[string]interface{}{
5353
"name": "cm-one",
5454
"namespace": "list-simple-integration-testing",
55+
"labels": map[string]interface{}{
56+
"ns": "list-simple-integration-testing",
57+
},
5558
},
5659
},
5760
},
@@ -67,6 +70,9 @@ func TestListSimpleRun(t *testing.T) {
6770
"metadata": map[string]interface{}{
6871
"name": "cm-two",
6972
"namespace": "list-simple-integration-testing",
73+
"labels": map[string]interface{}{
74+
"ns": "list-simple-integration-testing",
75+
},
7076
},
7177
},
7278
},
@@ -110,6 +116,9 @@ func TestListSimpleRun(t *testing.T) {
110116
"kind": "ConfigMap",
111117
"metadata": map[string]interface{}{
112118
"namespace": "list-simple-integration-testing",
119+
"labels": map[string]interface{}{
120+
"ns": "list-simple-integration-testing",
121+
},
113122
},
114123
},
115124
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/e2e/suite.sh test/declarative/suite.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ echo -e "\n Apply d-operators based ci to K3s cluster"
9494
k3s kubectl apply -f ci.yaml
9595

9696
echo -e "\n Apply test experiments to K3s cluster"
97-
k3s kubectl apply -f ./../experiments/
97+
k3s kubectl apply -f ./experiments/
9898

9999
echo -e "\n Apply ci inference to K3s cluster"
100100
k3s kubectl apply -f inference.yaml

0 commit comments

Comments
 (0)