Skip to content

Commit 876abeb

Browse files
authored
test: add component test (#567)
* test: add component test Signed-off-by: Chen Keinan <[email protected]> * test: add component test Signed-off-by: Chen Keinan <[email protected]> --------- Signed-off-by: Chen Keinan <[email protected]>
1 parent 482110b commit 876abeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2118
-0
lines changed

.github/workflows/component-test.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# File: .github/workflows/docker-go-build.yml
2+
name: gitops-runtime-helm
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- "*.md"
10+
- charts/**
11+
pull_request:
12+
branches:
13+
- main
14+
paths-ignore:
15+
- "*.md"
16+
- charts/**
17+
18+
jobs:
19+
component-test:
20+
runs-on: ubuntu-latest
21+
22+
env:
23+
DOCKER_CLI_EXPERIMENTAL: enabled
24+
# Enable BuildKit
25+
DOCKER_BUILDKIT: 1
26+
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up QEMU
32+
uses: docker/setup-qemu-action@v3
33+
34+
- name: Set up Docker Buildx
35+
id: buildx
36+
uses: docker/setup-buildx-action@v3
37+
- name: Set up kubectl
38+
uses: azure/setup-kubectl@v3
39+
with:
40+
version: 'v1.29.0'
41+
- name: Install K3d
42+
run: |
43+
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
44+
k3d --version
45+
46+
- name: Create K3d cluster
47+
run: |
48+
k3d cluster create test-cluster --wait
49+
kubectl get nodes
50+
51+
- name: install kuttl
52+
run: |
53+
mkdir -p ./bin
54+
curl -L https://github.com/kudobuilder/kuttl/releases/download/v0.22.0/kubectl-kuttl_0.22.0_linux_x86_64 -o ./bin/kuttl;
55+
56+
chmod +x ./bin/kuttl;
57+
- name: Install jq
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y jq
61+
- name: install helm
62+
run: |
63+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
64+
65+
chmod 700 get_helm.sh
66+
67+
./get_helm.sh
68+
helm repo add gitea-charts https://dl.gitea.com/charts/
69+
helm repo add mockserver https://www.mock-server.com
70+
71+
72+
- name: Run KUTTL tests
73+
run: |
74+
cd tests/component-tests && ./../../bin/kuttl test --parallel 1 --start-kind=false --namespace e2e-test --config startup.yaml

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ output
1515
values-dev*
1616
dry-run.yaml
1717
.debug
18+
bin
19+
# Test
20+
cmd/__debug_*
21+
/test/component-tests/setup/simple-app
22+
/test/component-tests/setup/codefresh-isc
23+
**/test/component-tests/setup/values/runtime.values.yaml
24+
**/test/component-tests/promotion/01-gitCommit/commit.json
25+
**/test/component-tests/kubeconfig
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -----------------------------------------------------------------------------
2+
# 00-assert.yaml - KUTTL TestAssert for drag-and-drop workflow status
3+
#
4+
# This TestAssert script checks the status of the workflow created by the
5+
# drag-and-drop test in the Codefresh GitOps Operator component tests.
6+
#
7+
# Usage:
8+
# This assertion is executed as part of the KUTTL test suite.
9+
#
10+
# Steps performed:
11+
# - Queries the workflow status for the specific release.
12+
# - Asserts that the workflow status is 'Succeeded'.
13+
# -----------------------------------------------------------------------------
14+
---
15+
apiVersion: kuttl.dev/v1beta1
16+
commands:
17+
- script: >
18+
STATUS="$(kubectl get workflow -n codefresh -l codefresh.io/release=682051c15f0ea1658a3eed78 -o jsonpath="{.items[*].status.phase}")"
19+
20+
if [ $STATUS = 'Succeeded' ]; then
21+
echo "workflow status for release '682051c15f0ea1658a3eed78' has succeeded"
22+
else
23+
echo "workflow status ($STATUS) for release '682051c15f0ea1658a3eed78' should be succeeded"
24+
exit 1
25+
fi
26+
kind: TestAssert
27+
timeout: 240
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -----------------------------------------------------------------------------
2+
# 00-drag-and-drop-task.yaml - KUTTL TestStep for drag-and-drop mock setup
3+
#
4+
# This TestStep runs the dragAndDrop.sh script to load drag-and-drop mock
5+
# expectations into Mockserver for the Codefresh GitOps Operator component tests.
6+
#
7+
# Usage:
8+
# This step is executed as part of the KUTTL test suite.
9+
#
10+
# Steps performed:
11+
# - Executes the dragAndDrop.sh script to configure Mockserver.
12+
# -----------------------------------------------------------------------------
13+
---
14+
apiVersion: kuttl.dev/v1beta1
15+
kind: TestStep
16+
commands:
17+
- script: ./dragAndDrop.sh
18+
timeout: 30
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"httpRequest": {
4+
"method": "POST",
5+
"path": "/2.0/api/graphql",
6+
"body": {
7+
"query": "\nquery productReleaseTasks {\n\tproductReleaseTasks {\n\t\ttype\n\t\tlabels\n\t\tcommitInfo {\n\t\t\tsha\n\t\t\tcommitter\n\t\t\tdate\n\t\t\tmessage\n\t\t}\n\t\tappNamespace\n\t\tappName\n\t\trepoUrl\n\t\tbranch\n\t\tpath\n\t\tpostActionOnly\n\t\tpreAction\n\t\tactionUrl\n\t\tactionBody\n\t\tpostAction\n\t\tworkflowNamespace\n\t\tworkflowName\n\t}\n}",
8+
"variables": {}
9+
}
10+
},
11+
"httpResponse": {
12+
"statusCode": 200,
13+
"body": {
14+
"data": {
15+
"productReleaseTasks": [
16+
{
17+
"type": "CreateProductReleaseTask",
18+
"labels": {
19+
"codefresh.io/product": "simple",
20+
"codefresh.io/env": "prod",
21+
"codefresh.io/release": "682051c15f0ea1658a3eed78",
22+
"codefresh.io/promotion-flow": "",
23+
"codefresh.io/app-name": "simple-prod",
24+
"codefresh.io/app-namespace": "codefresh",
25+
"codefresh.io/release-name": "3ab912d13"
26+
},
27+
"commitInfo": null,
28+
"appNamespace": "codefresh",
29+
"appName": "simple-prod",
30+
"repoUrl": "http://gitea-http.gitea:3000/test-owner/simple-app.git",
31+
"branch": "HEAD",
32+
"path": ".",
33+
"postActionOnly": false,
34+
"preAction": null,
35+
"actionUrl": "/api/graphql",
36+
"actionBody": "{\"query\":\"\\n mutation commitFiles($args: CommitFilesArgs!) {\\n commitFiles(args: $args) {\\n COMMIT_SHA: sha\\n sha\\n message\\n date\\n committer {\\n name\\n email\\n }\\n }\\n }\\n\",\"variables\":{\"args\":{\"msg\":\"promote codefresh/simple-dev to codefresh/simple-prod\",\"description\":\"\",\"files\":[{\"path\":\"values.yaml\",\"revision\":\"f238c105280eaf3a045d261f2caa1e423d8b4473\",\"data\":\"# Default values for simple-app.\\n# This is a YAML-formatted file.\\n# Declare variables to be passed into your templates.\\n\\nreplicaCount: 1\\n\\nimage:\\n repository: wang/alpine-go-echo-server\\n # sed -i -e \\\"s/^\\\\( tag:\\\\).*/\\\\1 $CI_COMMIT_SHA/\\\" ops/values.yaml\\n tag: 0.1\\n pullPolicy: IfNotPresent\\n\\nimagePullSecrets: []\\nnameOverride: \\\"\\\"\\nfullnameOverride: \\\"\\\"\\ncomponents:\\n - test1\\napp:\\n name: my-app-name\\n command:\\n - \\\"/app/echo-server\\\"\\n port: 3000\\n ## Enabled 'ports' If additional ports are needed\\n # ports:\\n # - name: port2\\n # containerPort: 3002\\n # protocol: TCP\\n # - name: port3\\n # containerPort: 3003\\n # protocol: UDP\\n config:\\n test_env: \\\"This is test value\\\"\\n secrets: false # To enable secretRef, you need create a secret named as RELEASE-NAME-secrets\\n # livenessProbe:\\n # httpGet:\\n # path: /\\n # port: http\\n # readinessProbe:\\n # httpGet:\\n # path: /\\n # port: http\\n volumeMounts: []\\n # - name: demo-data\\n # mountPath: /mnt/data\\n # readonly: true\\n\\nsidecar:\\n name: my-app-name-sidecar\\n enabled: false\\n image:\\n tag: 0.1\\n repository: wang/alpine-go-echo-server\\n pullPolicy: IfNotPresent\\n port: 3001\\n command:\\n - \\\"/app/echo-server\\\"\\n volumeMounts: []\\n resources:\\n limits:\\n cpu: 100m\\n memory: 128Mi\\n\\n\\nvolumes: []\\n # - name: demo-data\\n # secret:\\n # secretName: demo-secrets\\n\\nserviceAccount:\\n # Specifies whether a service account should be created\\n create: true\\n # Annotations to add to the service account\\n annotations: {}\\n # The name of the service account to use.\\n # If not set and create is true, a name is generated using the fullname template\\n name:\\n\\npodSecurityContext: {}\\n # fsGroup: 2000\\n\\nsecurityContext: {}\\n # capabilities:\\n # drop:\\n # - ALL\\n # readOnlyRootFilesystem: true\\n # runAsNonRoot: true\\n # runAsUser: 1000\\n\\nservice:\\n enabled: true\\n type: ClusterIP\\n port: 80\\n ## Enable 'ports', if additional ports are needed\\n # ports:\\n # - name: port2\\n # port: 3002\\n # targetPort: port2\\n # protocol: TCP\\n # - name: port3\\n # port: 3003\\n # targetPort: port3\\n # protocol: UDP\\n\\ningress:\\n enabled: false\\n annotations: {}\\n # kubernetes.io/ingress.class: nginx\\n # kubernetes.io/tls-acme: \\\"true\\\"\\n # cert-manager.io/cluster-issuer: letsencrypt-production\\n hosts:\\n - host: chart-example.local\\n paths: []\\n # - /\\n # - /index.html\\n tls: []\\n # - secretName: chart-example-tls\\n # hosts:\\n # - chart-example.local\\n\\nresources: {}\\n # We usually recommend not to specify default resources and to leave this as a conscious\\n # choice for the user. This also increases chances charts run on environments with little\\n # resources, such as Minikube. If you do want to specify resources, uncomment the following\\n # lines, adjust them as necessary, and remove the curly braces after 'resources:'.\\n # limits:\\n # cpu: 100m\\n # memory: 128Mi\\n # requests:\\n # cpu: 100m\\n # memory: 128Mi\\n\\nnodeSelector: {}\\n\\ntolerations: []\\n\\naffinity: {}\\n\"}],\"repo\":\"test-owner/simple-app\",\"branchName\":\"HEAD\",\"force\":true}}}",
37+
"postAction": null,
38+
"workflowNamespace": null,
39+
"workflowName": null
40+
}
41+
]
42+
}
43+
}
44+
},
45+
"times": {
46+
"remainingTimes": 1,
47+
"unlimited": false
48+
}
49+
},
50+
{
51+
"httpRequest": {
52+
"method": "POST",
53+
"path": "/2.0/api/graphql",
54+
"body": {
55+
"query": "\nquery productReleaseRunHooksTasks {\n\tproductReleaseRunHooksTasks {\n\t\ttype\n\t\tlabels\n\t\tworkflowTemplateName\n\t\tworkflowNamespace\n\t\tworkflowName\n\t\tparameters\n\t}\n}",
56+
"variables": {}
57+
}
58+
},
59+
"httpResponse": {
60+
"statusCode": 200,
61+
"body": {
62+
"data": {
63+
"productReleaseRunHooksTasks": []
64+
}
65+
}
66+
}
67+
},
68+
{
69+
"httpRequest": {
70+
"method": "POST",
71+
"path": "/2.0/api/graphql",
72+
"body": {
73+
"query": "\nquery productReleaseCommitStatuses {\n\tproductReleaseCommitStatuses {\n\t\tsha\n\t\trepoURL\n\t\tstatus\n\t\tdescription\n\t\tcontext\n\t\ttargetUrl\n\t}\n}",
74+
"variables": {}
75+
}
76+
},
77+
"httpResponse": {
78+
"statusCode": 200,
79+
"body": {
80+
"data": {
81+
"productReleaseCommitStatuses": []
82+
}
83+
}
84+
}
85+
}
86+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# dragAndDrop.sh - Loads drag-and-drop mock expectations for component tests
4+
#
5+
# This script loads mock expectations into the Mockserver for drag-and-drop
6+
# scenarios in the Codefresh GitOps Operator component test suite.
7+
#
8+
# Usage:
9+
# ./dragAndDrop.sh
10+
#
11+
# Steps performed:
12+
# - Waits briefly to ensure Mockserver is ready.
13+
# - Loads drag-and-drop mock expectations from dragAndDrop.json.
14+
# -----------------------------------------------------------------------------
15+
sleep 2
16+
curl -i -X PUT http://127.0.0.1:1080/mockserver/expectation --data-binary "@./dragAndDrop.json"

0 commit comments

Comments
 (0)