Skip to content

Commit

Permalink
test: add no-extra-param tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madbence committed Oct 25, 2020
1 parent 55cbf7d commit 7218c6b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 4 deletions.
48 changes: 48 additions & 0 deletions regression-tests/__snapshots__/regresion.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,54 @@ Array [
"path": "./regression-tests/no-duplicate-param.yaml",
"rule": "no-duplicate-param",
},
Object {
"level": "error",
"loc": Object {
"endColumn": 1,
"endLine": 21,
"range": Array [
301,
332,
],
"startColumn": 11,
"startLine": 19,
},
"message": "Pipeline 'no-extra-param-pipeline' references task 'no-extra-param-task' (as 'step-1'), and supplies parameter 'foo' to it, but it's not a valid parameter",
"path": "./regression-tests/no-extra-param.yaml",
"rule": "no-extra-param",
},
Object {
"level": "error",
"loc": Object {
"endColumn": 1,
"endLine": 27,
"range": Array [
409,
440,
],
"startColumn": 11,
"startLine": 25,
},
"message": "Pipeline 'no-extra-param-pipeline' references task 'step-1', and supplies parameter 'foo' to it, but it's not a valid parameter",
"path": "./regression-tests/no-extra-param.yaml",
"rule": "no-extra-param",
},
Object {
"level": "error",
"loc": Object {
"endColumn": 1,
"endLine": 44,
"range": Array [
774,
807,
],
"startColumn": 13,
"startLine": 42,
},
"message": "TriggerTemplate 'no-extra-param-template' references pipeline 'no-extra-param-pipeline', and supplies 'foo', but it's not a valid parameter.",
"path": "./regression-tests/no-extra-param.yaml",
"rule": "no-extra-param",
},
Object {
"level": "warning",
"loc": Object {
Expand Down
65 changes: 65 additions & 0 deletions regression-tests/no-extra-param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: no-extra-param-task
spec:
steps: []
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: no-extra-param-pipeline
spec:
tasks:
- name: step-1
taskRef:
name: no-extra-param-task
params:
- name: foo
value: foo
- name: step-1
taskSpec:
steps: []
params:
- name: foo
value: foo
---
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: no-extra-param-template
spec:
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipeline-run-1
spec:
pipelineRef:
name: no-extra-param-pipeline
params:
- name: foo
value: foo
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipeline-run-2
spec:
pipelineSpec:
tasks:
- name: step-1
taskRef:
name: no-extra-param-task
params:
- name: foo
value: foo
- name: step-2
taskSpec:
steps: []
params:
- name: foo
value: foo
params:
- name: foo
value: foo
4 changes: 2 additions & 2 deletions src/rules/no-extra-param.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function getTaskParams(spec) {
if (spec.inputs) return spec.inputs.params;
return spec.params;
if (spec.inputs) return spec.inputs.params ?? [];
return spec.params ?? [];
}

export default (docs, tekton, report) => {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-missing-param.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function getTaskParams(spec) {
if (spec.inputs) return spec.inputs.params;
return spec.params;
if (spec.inputs) return spec.inputs.params ?? [];
return spec.params ?? [];
}

export default (docs, tekton, report) => {
Expand Down

0 comments on commit 7218c6b

Please sign in to comment.