mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-24 06:15:46 +00:00
Support response files in fixtures
Extend to test logic to be able to load the fixture reponse from a file, so that we don't have to inline a long JSON doc into the fixture config YAML. This is achieved by creating a config map with all the files in the fixtures folder, and mounting that configmap as a volume to the sidecar. This allows improving the test for the github-add-comment task v0.4 Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
This commit is contained in:
parent
66df9ddf53
commit
67fde32738
@ -6,3 +6,11 @@ response:
|
||||
status: 200
|
||||
output: '{"status": 200}'
|
||||
content-type: text/json
|
||||
---
|
||||
headers:
|
||||
method: GET
|
||||
path: /repos/{repo:[^/]+/[^/]+}/issues/{issue:[0-9]+}/comments
|
||||
response:
|
||||
status: 200
|
||||
content-type: text/json
|
||||
file: /fixtures/list-comment-response.json
|
66
task/github-add-comment/0.4/tests/fixtures/list-comment-response.json
vendored
Normal file
66
task/github-add-comment/0.4/tests/fixtures/list-comment-response.json
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
[
|
||||
{
|
||||
"url": "https://api.github.com/repos/tektoncd/plumbing/issues/comments/111111111111",
|
||||
"html_url": "https://github.com/tektoncd/plumbing/pull/111#issuecomment-111111111111",
|
||||
"issue_url": "https://api.github.com/repos/tektoncd/plumbing/issues/111",
|
||||
"id": 111111111111,
|
||||
"node_id": "abcd==",
|
||||
"user": {
|
||||
"login": "johndoe",
|
||||
"id": 12345,
|
||||
"node_id": "MDQ6VXNlcjk4OTgw",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/12345?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/johndoe",
|
||||
"html_url": "https://github.com/johndoe",
|
||||
"followers_url": "https://api.github.com/users/johndoe/followers",
|
||||
"following_url": "https://api.github.com/users/johndoe/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/johndoe/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/johndoe/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/johndoe/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/johndoe/orgs",
|
||||
"repos_url": "https://api.github.com/users/johndoe/repos",
|
||||
"events_url": "https://api.github.com/users/johndoe/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/johndoe/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"created_at": "2021-01-18T12:56:24Z",
|
||||
"updated_at": "2021-01-18T12:56:24Z",
|
||||
"author_association": "MEMBER",
|
||||
"body": "/kind feature",
|
||||
"performed_via_github_app": null
|
||||
},
|
||||
{
|
||||
"url": "https://api.github.com/repos/tektoncd/plumbing/issues/comments/2222222222",
|
||||
"html_url": "https://github.com/tektoncd/plumbing/pull/111#issuecomment-2222222222",
|
||||
"issue_url": "https://api.github.com/repos/tektoncd/plumbing/issues/111",
|
||||
"id": 2222222222,
|
||||
"node_id": "MDEyOklzc3VlQ29tbWVudDc2MjIzNDExNg==",
|
||||
"user": {
|
||||
"login": "johndoe",
|
||||
"id": 12345,
|
||||
"node_id": "123abc123",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/12345?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/johndoe",
|
||||
"html_url": "https://github.com/johndoe",
|
||||
"followers_url": "https://api.github.com/users/johndoe/followers",
|
||||
"following_url": "https://api.github.com/users/johndoe/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/johndoe/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/johndoe/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/johndoe/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/johndoe/orgs",
|
||||
"repos_url": "https://api.github.com/users/johndoe/repos",
|
||||
"events_url": "https://api.github.com/users/johndoe/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/johndoe/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"created_at": "2021-01-18T12:57:02Z",
|
||||
"updated_at": "2021-01-18T12:57:02Z",
|
||||
"author_association": "MEMBER",
|
||||
"body": "A comment to replace<!-- TEST_TAG123 -->",
|
||||
"performed_via_github_app": null
|
||||
}
|
||||
]
|
@ -21,6 +21,10 @@ spec:
|
||||
value: "Hello from TektonCD test"
|
||||
- name: REQUEST_URL
|
||||
value: https://github.com/tektoncd/catalog/issues/1
|
||||
- name: REPLACE
|
||||
value: "true"
|
||||
- name: COMMENT_TAG
|
||||
value: TEST_TAG123
|
||||
---
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: PipelineRun
|
||||
|
@ -181,32 +181,37 @@ function test_task_creation() {
|
||||
# In case of rerun it's fine to ignore this error
|
||||
${KUBECTL_CMD} create namespace ${tns} >/dev/null 2>/dev/null || :
|
||||
|
||||
# Install the task itself first
|
||||
for yaml in ${taskdir}/*.yaml;do
|
||||
started=$(date '+%Hh%M:%S')
|
||||
echo "${started} STARTING: ${testname}/${version} "
|
||||
cp ${yaml} ${TMPF}
|
||||
[[ -f ${taskdir}/tests/pre-apply-task-hook.sh ]] && source ${taskdir}/tests/pre-apply-task-hook.sh
|
||||
function_exists pre-apply-task-hook && pre-apply-task-hook
|
||||
# Install the task itself first. We can only have one YAML file
|
||||
yaml=$(printf ${taskdir}/*.yaml)
|
||||
started=$(date '+%Hh%M:%S')
|
||||
echo "${started} STARTING: ${testname}/${version} "
|
||||
cp ${yaml} ${TMPF}
|
||||
[[ -f ${taskdir}/tests/pre-apply-task-hook.sh ]] && source ${taskdir}/tests/pre-apply-task-hook.sh
|
||||
function_exists pre-apply-task-hook && pre-apply-task-hook
|
||||
|
||||
[[ -d ${taskdir}/tests/fixtures ]] && {
|
||||
cat <<EOF>>${TMPF}
|
||||
[[ -d ${taskdir}/tests/fixtures ]] && {
|
||||
# Create a configmap to make every file under fixture
|
||||
# available to the sidecar.
|
||||
${KUBECTL_CMD} -n ${tns} create configmap fixtures --from-file=${taskdir}/tests/fixtures
|
||||
cat <<EOF>>${TMPF}
|
||||
sidecars:
|
||||
- image: quay.io/chmouel/go-rest-api-test
|
||||
name: go-rest-api
|
||||
volumeMounts:
|
||||
- name: fixtures
|
||||
mountPath: /fixtures
|
||||
env:
|
||||
- name: CONFIG
|
||||
value: |
|
||||
$(cat ${taskdir}/tests/fixtures/*.yaml|sed 's/^/ /')
|
||||
EOF
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure we have deleted the content, this is in case of rerun
|
||||
# and namespace hasn't been cleaned up or there is some Cluster*
|
||||
# stuff, which really should not be allowed.
|
||||
${KUBECTL_CMD} -n ${tns} delete -f ${TMPF} >/dev/null 2>/dev/null || true
|
||||
${KUBECTL_CMD} -n ${tns} create -f ${TMPF}
|
||||
done
|
||||
# Make sure we have deleted the content, this is in case of rerun
|
||||
# and namespace hasn't been cleaned up or there is some Cluster*
|
||||
# stuff, which really should not be allowed.
|
||||
${KUBECTL_CMD} -n ${tns} delete -f ${TMPF} >/dev/null 2>/dev/null || true
|
||||
${KUBECTL_CMD} -n ${tns} create -f ${TMPF}
|
||||
|
||||
# Install resource and run
|
||||
for yaml in ${runtest}/*.yaml;do
|
||||
@ -214,6 +219,19 @@ EOF
|
||||
[[ -f ${taskdir}/tests/pre-apply-taskrun-hook.sh ]] && source ${taskdir}/tests/pre-apply-taskrun-hook.sh
|
||||
function_exists pre-apply-taskrun-hook && pre-apply-taskrun-hook
|
||||
|
||||
# If we have fixtures, add a volume to the taskrun to mount
|
||||
# the fixtures configmap. This only works as long as the original
|
||||
# TaskRun does not use podTemplate
|
||||
[[ -d ${taskdir}/tests/fixtures ]] && {
|
||||
cat <<EOF>>${TMPF}
|
||||
podTemplate:
|
||||
volumes:
|
||||
- name: fixtures
|
||||
configMap:
|
||||
name: fixtures
|
||||
EOF
|
||||
}
|
||||
|
||||
# Make sure we have deleted the content, this is in case of rerun
|
||||
# and namespace hasn't been cleaned up or there is some Cluster*
|
||||
# stuff, which really should not be allowed.
|
||||
|
Loading…
Reference in New Issue
Block a user