Skip to content

Commit 9184fd1

Browse files
authored
Issues/84 - getting started with e2e testing - can run promotion pull request scenarios (#126)
* e2e for promotions pull request * bump version * review suggestions
1 parent d511a7a commit 9184fd1

33 files changed

+1054
-22
lines changed

CONTRIBUTING.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ by Go to download dependencies from private repositories (replace `USERNAME` wit
1717

1818
## Running Tests
1919

20+
The project has unit, integration and end-to-end testing. For all of them we are using `go test` for all test types
21+
(including e2e) due to its simplicity.
22+
2023
### Unit Testing
2124

2225
This project has unit tests
@@ -25,7 +28,8 @@ This project has unit tests
2528
make test
2629
```
2730

28-
Testing on this controller follows closely what is done by default in `kubebuilder` although we ditched the use of `Gomega` in favor of native Go testing structure. As an example on how to write tests for this controller you can take a look at Kubebuilder [docs](https://book.kubebuilder.io/cronjob-tutorial/writing-tests.html#writing-controller-tests) for reference.
31+
Testing on this controller follows closely what is done by default in `kubebuilder` although we ditched the use of `Gomega` in favor of native Go testing structure.
32+
As an example on how to write tests for this controller you can take a look at Kubebuilder [docs](https://book.kubebuilder.io/cronjob-tutorial/writing-tests.html#writing-controller-tests) for reference.
2933

3034
### Integration Testing
3135

@@ -53,8 +57,66 @@ where you would need to add the build tag `integration`
5357

5458
```go
5559
//go:build integration
60+
```
5661

62+
### End-to-End testing
63+
64+
This project has a test suite for end to end pipeline controller journeys. You could find them
65+
within [e2e folder](./e2e).
66+
67+
#### Configuration
68+
69+
A set of [test pipelines](/e2e/testdata/pipelines) exists to run the tests. They depend on a set
70+
of common resources.
71+
72+
A set of git repos are required to hold the manifests to use during pull request promotion strategy.
73+
74+
- [github repo](https://github.com/weaveworks/pipeline-controller-e2e)
75+
- [gitlab repo](https://gitlab.git.dev.weave.works/pipeline-controller/pipeline-controller-e2e)
76+
77+
A [set of credentials](https://docs.gitops.weave.works/docs/pipelines/promoting-applications/#create-credentials-secret)
78+
per git provider needs to exist.
79+
80+
```yaml
81+
apiVersion: v1
82+
data:
83+
password: <my-github-pat>
84+
token: <my-github-pat>
85+
username: <my-github-username>
86+
kind: Secret
87+
metadata:
88+
name: github-promotion-credentials
89+
namespace: flux-system
90+
type: Opaque
91+
---
92+
apiVersion: v1
93+
data:
94+
password: <my-gitlab-pat>
95+
token: <my-gitlab-pat>
96+
username: <my-gitlab-username>
97+
kind: Secret
98+
metadata:
99+
name: gitlab-promotion-credentials
100+
namespace: flux-system
101+
type: Opaque
57102
```
103+
#### Running the tests
104+
105+
Execute `make e2e` to exercise the test.
106+
107+
In order to interact with them the following targets exists in [Makefile](./Makefile):
108+
109+
- `e2e-setup`: provisions a local environment with kind, flux and pipeline controller to run the tests.
110+
- `e2e-test`: runs the tests against the running environment.
111+
- `e2e-clean`: tears down the created environment.
112+
- `e2e`: single target that executes setup + test + clean targets
113+
114+
One of the concerns with end-to-end testing is that tend to be unstable. A simple script to test how stable
115+
is the test suite could be used [stability script](/hack/e2e-suite-stability.sh).
116+
117+
#### Adding a test
118+
119+
Add your test case within the e2e folder. An example is [promotion_pull_request_test.go](e2e/promotion_pull_request_test.go)
58120

59121
## Working with promotions
60122

Makefile

+24-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test: manifests generate fmt vet envtest ## Run tests.
9292

9393
.PHONY: integration-test
9494
integration-test:
95-
go test -tags integration -v ./...
95+
go test -tags integration -cover -v ./...
9696

9797
.PHONY: lint-and-install-chart
9898
lint-and-install-chart:
@@ -207,3 +207,26 @@ $(GOLANGCI_LINT): $(LOCALBIN)
207207
helm: $(HELM)
208208
$(HELM): $(LOCALBIN)
209209
test -s $(LOCALBIN)/helm || { curl -s https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | HELM_INSTALL_DIR=$(LOCALBIN) bash -s -- --no-sudo --version $(HELM_VERSION); }
210+
211+
.PHONY: e2e
212+
e2e: e2e-setup e2e-test e2e-clean
213+
214+
.PHONY: e2e-setup
215+
e2e-setup: docker-build kind flux deploy
216+
kubectl wait -n pipeline-system deployment/pipeline-controller --for=condition=available
217+
kubectl apply -f e2e/testdata --recursive
218+
219+
kind:
220+
kind create cluster --name=pipeline-controller || kubectx kind-pipeline-controller
221+
kind load docker-image --name=pipeline-controller $(IMG)
222+
223+
flux:
224+
flux install
225+
226+
.PHONY: e2e-test
227+
e2e-test:
228+
go test -tags e2e -count=1 -v ./e2e
229+
230+
.PHONY: e2e-clean
231+
e2e-clean:
232+
kind delete cluster --name=pipeline-controller

api/v1alpha1/pipeline_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type PipelineSpec struct {
6161
// Promotion defines all the available promotion strategies. All of the fields in here are mutually exclusive, i.e. you can only select one
6262
// promotion strategy per Pipeline. Failure to do so will result in undefined behaviour.
6363
type Promotion struct {
64-
// PullRequest defines a promotion through a GitHub Pull Request.
64+
// PullRequest defines a promotion through a pull request
6565
// +optional
6666
PullRequest *PullRequestPromotion `json:"pull-request,omitempty"`
6767
// Notification defines a promotion where an event is emitted through Flux's notification-controller each time an app is to be promoted.
@@ -98,7 +98,7 @@ type PullRequestPromotion struct {
9898
// +optional
9999
Branch string `json:"branch"`
100100
// SecretRef specifies the Secret containing authentication credentials for
101-
// the git repository and for the GitHub API.
101+
// the git repository and for the git provider API.
102102
// For HTTPS repositories the Secret must contain 'username' and 'password'
103103
// fields.
104104
// For SSH repositories the Secret must contain 'identity'

charts/pipeline-controller/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: pipeline-controller
33
description: Pipeline-controller Helm chart for Weave GitOps Enterprise
44
type: application
5-
version: 0.9.0
5+
version: 0.10.0
66
appVersion: "v0.0.26"

charts/pipeline-controller/crds/pipelines.weave.works_pipelines.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ spec:
132132
app is to be promoted.
133133
type: object
134134
pull-request:
135-
description: PullRequest defines a promotion through a GitHub
136-
Pull Request.
135+
description: PullRequest defines a promotion through a pull request
137136
properties:
138137
branch:
139138
description: 'The branch to checkout after cloning. Note:
@@ -144,8 +143,8 @@ spec:
144143
type: string
145144
secretRef:
146145
description: SecretRef specifies the Secret containing authentication
147-
credentials for the git repository and for the GitHub API.
148-
For HTTPS repositories the Secret must contain 'username'
146+
credentials for the git repository and for the git provider
147+
API. For HTTPS repositories the Secret must contain 'username'
149148
and 'password' fields. For SSH repositories the Secret must
150149
contain 'identity' and 'known_hosts' fields. For Git Provider
151150
API to manage pull requests, it must contain a 'token' field.

config/crd/bases/pipelines.weave.works_pipelines.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ spec:
132132
app is to be promoted.
133133
type: object
134134
pull-request:
135-
description: PullRequest defines a promotion through a GitHub
136-
Pull Request.
135+
description: PullRequest defines a promotion through a pull request
137136
properties:
138137
branch:
139138
description: 'The branch to checkout after cloning. Note:
@@ -144,8 +143,8 @@ spec:
144143
type: string
145144
secretRef:
146145
description: SecretRef specifies the Secret containing authentication
147-
credentials for the git repository and for the GitHub API.
148-
For HTTPS repositories the Secret must contain 'username'
146+
credentials for the git repository and for the git provider
147+
API. For HTTPS repositories the Secret must contain 'username'
149148
and 'password' fields. For SSH repositories the Secret must
150149
contain 'identity' and 'known_hosts' fields. For Git Provider
151150
API to manage pull requests, it must contain a 'token' field.

0 commit comments

Comments
 (0)