Skip to content

test: add component test #567

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

Merged
merged 3 commits into from
Jul 9, 2025
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
74 changes: 74 additions & 0 deletions .github/workflows/component-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# File: .github/workflows/docker-go-build.yml
name: gitops-runtime-helm

on:
push:
branches:
- main
paths-ignore:
- "*.md"
- charts/**
pull_request:
branches:
- main
paths-ignore:
- "*.md"
- charts/**

jobs:
component-test:
runs-on: ubuntu-latest

env:
DOCKER_CLI_EXPERIMENTAL: enabled
# Enable BuildKit
DOCKER_BUILDKIT: 1

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'v1.29.0'
- name: Install K3d
run: |
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
k3d --version

- name: Create K3d cluster
run: |
k3d cluster create test-cluster --wait
kubectl get nodes

- name: install kuttl
run: |
mkdir -p ./bin
curl -L https://github.com/kudobuilder/kuttl/releases/download/v0.22.0/kubectl-kuttl_0.22.0_linux_x86_64 -o ./bin/kuttl;

chmod +x ./bin/kuttl;
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: install helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3

chmod 700 get_helm.sh

./get_helm.sh
helm repo add gitea-charts https://dl.gitea.com/charts/
helm repo add mockserver https://www.mock-server.com


- name: Run KUTTL tests
run: |
cd tests/component-tests && ./../../bin/kuttl test --parallel 1 --start-kind=false --namespace e2e-test --config startup.yaml
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ output
values-dev*
dry-run.yaml
.debug
bin
# Test
cmd/__debug_*
/test/component-tests/setup/simple-app
/test/component-tests/setup/codefresh-isc
**/test/component-tests/setup/values/runtime.values.yaml
**/test/component-tests/promotion/01-gitCommit/commit.json
**/test/component-tests/kubeconfig
27 changes: 27 additions & 0 deletions tests/component-tests/promotion/00-dragAndDrop/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -----------------------------------------------------------------------------
# 00-assert.yaml - KUTTL TestAssert for drag-and-drop workflow status
#
# This TestAssert script checks the status of the workflow created by the
# drag-and-drop test in the Codefresh GitOps Operator component tests.
#
# Usage:
# This assertion is executed as part of the KUTTL test suite.
#
# Steps performed:
# - Queries the workflow status for the specific release.
# - Asserts that the workflow status is 'Succeeded'.
# -----------------------------------------------------------------------------
---
apiVersion: kuttl.dev/v1beta1
commands:
- script: >
STATUS="$(kubectl get workflow -n codefresh -l codefresh.io/release=682051c15f0ea1658a3eed78 -o jsonpath="{.items[*].status.phase}")"

if [ $STATUS = 'Succeeded' ]; then
echo "workflow status for release '682051c15f0ea1658a3eed78' has succeeded"
else
echo "workflow status ($STATUS) for release '682051c15f0ea1658a3eed78' should be succeeded"
exit 1
fi
kind: TestAssert
timeout: 240
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -----------------------------------------------------------------------------
# 00-drag-and-drop-task.yaml - KUTTL TestStep for drag-and-drop mock setup
#
# This TestStep runs the dragAndDrop.sh script to load drag-and-drop mock
# expectations into Mockserver for the Codefresh GitOps Operator component tests.
#
# Usage:
# This step is executed as part of the KUTTL test suite.
#
# Steps performed:
# - Executes the dragAndDrop.sh script to configure Mockserver.
# -----------------------------------------------------------------------------
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: ./dragAndDrop.sh
timeout: 30
86 changes: 86 additions & 0 deletions tests/component-tests/promotion/00-dragAndDrop/dragAndDrop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"httpRequest": {
"method": "POST",
"path": "/2.0/api/graphql",
"body": {
"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}",
"variables": {}
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"data": {
"productReleaseTasks": [
{
"type": "CreateProductReleaseTask",
"labels": {
"codefresh.io/product": "simple",
"codefresh.io/env": "prod",
"codefresh.io/release": "682051c15f0ea1658a3eed78",
"codefresh.io/promotion-flow": "",
"codefresh.io/app-name": "simple-prod",
"codefresh.io/app-namespace": "codefresh",
"codefresh.io/release-name": "3ab912d13"
},
"commitInfo": null,
"appNamespace": "codefresh",
"appName": "simple-prod",
"repoUrl": "http://gitea-http.gitea:3000/test-owner/simple-app.git",
"branch": "HEAD",
"path": ".",
"postActionOnly": false,
"preAction": null,
"actionUrl": "/api/graphql",
"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}}}",
"postAction": null,
"workflowNamespace": null,
"workflowName": null
}
]
}
}
},
"times": {
"remainingTimes": 1,
"unlimited": false
}
},
{
"httpRequest": {
"method": "POST",
"path": "/2.0/api/graphql",
"body": {
"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}",
"variables": {}
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"data": {
"productReleaseRunHooksTasks": []
}
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/2.0/api/graphql",
"body": {
"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}",
"variables": {}
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"data": {
"productReleaseCommitStatuses": []
}
}
}
}
]
16 changes: 16 additions & 0 deletions tests/component-tests/promotion/00-dragAndDrop/dragAndDrop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# dragAndDrop.sh - Loads drag-and-drop mock expectations for component tests
#
# This script loads mock expectations into the Mockserver for drag-and-drop
# scenarios in the Codefresh GitOps Operator component test suite.
#
# Usage:
# ./dragAndDrop.sh
#
# Steps performed:
# - Waits briefly to ensure Mockserver is ready.
# - Loads drag-and-drop mock expectations from dragAndDrop.json.
# -----------------------------------------------------------------------------
sleep 2
curl -i -X PUT http://127.0.0.1:1080/mockserver/expectation --data-binary "@./dragAndDrop.json"
Loading