From 9293920f2aa2426b7a30e35be4d472f3a40e6cc3 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sat, 6 Jun 2020 18:46:08 +0200 Subject: [PATCH] add test to validate a folder --- acceptance.bats | 6 + fixtures/blank.yaml | 0 fixtures/comment.yaml | 0 fixtures/duplicates-non-namespaced.yaml | 0 fixtures/duplicates-skipped-kinds.yaml | 0 .../duplicates-with-namespace-default.yaml | 0 fixtures/duplicates-with-namespace.yaml | 0 fixtures/duplicates.yaml | 0 fixtures/extra_property.yaml | 0 fixtures/folder/multi_valid.yaml | 181 ++++++++++++++++++ fixtures/folder/valid.yaml | 19 ++ fixtures/full_domain_group.yaml | 0 fixtures/int_or_string.yaml | 0 fixtures/invalid.yaml | 0 fixtures/list_invalid.yaml | 0 fixtures/list_valid.yaml | 0 fixtures/missing_kind.yaml | 0 fixtures/missing_kind_value.yaml | 0 fixtures/multi_invalid.yaml | 0 fixtures/multi_invalid_resources.yaml | 0 fixtures/multi_valid.yaml | 0 fixtures/multi_valid_source.yaml | 0 fixtures/null_array.yaml | 0 fixtures/null_string.yaml | 0 fixtures/quantity.yaml | 0 fixtures/same-kind-different-api.yaml | 0 ...me-object-different-namespace-default.yaml | 0 fixtures/same-object-different-namespace.yaml | 0 fixtures/test_crd.yaml | 0 fixtures/unconventional_keys.yaml | 0 fixtures/valid.json | 0 fixtures/valid.yaml | 0 fixtures/valid_version.yaml | 0 33 files changed, 206 insertions(+) mode change 100755 => 100644 fixtures/blank.yaml mode change 100755 => 100644 fixtures/comment.yaml mode change 100755 => 100644 fixtures/duplicates-non-namespaced.yaml mode change 100755 => 100644 fixtures/duplicates-skipped-kinds.yaml mode change 100755 => 100644 fixtures/duplicates-with-namespace-default.yaml mode change 100755 => 100644 fixtures/duplicates-with-namespace.yaml mode change 100755 => 100644 fixtures/duplicates.yaml mode change 100755 => 100644 fixtures/extra_property.yaml create mode 100644 fixtures/folder/multi_valid.yaml create mode 100644 fixtures/folder/valid.yaml mode change 100755 => 100644 fixtures/full_domain_group.yaml mode change 100755 => 100644 fixtures/int_or_string.yaml mode change 100755 => 100644 fixtures/invalid.yaml mode change 100755 => 100644 fixtures/list_invalid.yaml mode change 100755 => 100644 fixtures/list_valid.yaml mode change 100755 => 100644 fixtures/missing_kind.yaml mode change 100755 => 100644 fixtures/missing_kind_value.yaml mode change 100755 => 100644 fixtures/multi_invalid.yaml mode change 100755 => 100644 fixtures/multi_invalid_resources.yaml mode change 100755 => 100644 fixtures/multi_valid.yaml mode change 100755 => 100644 fixtures/multi_valid_source.yaml mode change 100755 => 100644 fixtures/null_array.yaml mode change 100755 => 100644 fixtures/null_string.yaml mode change 100755 => 100644 fixtures/quantity.yaml mode change 100755 => 100644 fixtures/same-kind-different-api.yaml mode change 100755 => 100644 fixtures/same-object-different-namespace-default.yaml mode change 100755 => 100644 fixtures/same-object-different-namespace.yaml mode change 100755 => 100644 fixtures/test_crd.yaml mode change 100755 => 100644 fixtures/unconventional_keys.yaml mode change 100755 => 100644 fixtures/valid.json mode change 100755 => 100644 fixtures/valid.yaml mode change 100755 => 100644 fixtures/valid_version.yaml diff --git a/acceptance.bats b/acceptance.bats index 4d529e4..6c71957 100755 --- a/acceptance.bats +++ b/acceptance.bats @@ -6,6 +6,12 @@ [ "$output" = "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0" ] } +@test "Pass when parsing a folder containing valid YAML files" { + run bin/kubeconform -summary fixtures/folder + [ "$status" -eq 0 ] + [ "$output" = "Summary: 7 resources found in 2 files - Valid: 7, Invalid: 0, Errors: 0 Skipped: 0" ] +} + @test "Pass when parsing a Kubernetes file with string and integer quantities" { run bin/kubeconform -verbose fixtures/quantity.yaml [ "$status" -eq 0 ] diff --git a/fixtures/blank.yaml b/fixtures/blank.yaml old mode 100755 new mode 100644 diff --git a/fixtures/comment.yaml b/fixtures/comment.yaml old mode 100755 new mode 100644 diff --git a/fixtures/duplicates-non-namespaced.yaml b/fixtures/duplicates-non-namespaced.yaml old mode 100755 new mode 100644 diff --git a/fixtures/duplicates-skipped-kinds.yaml b/fixtures/duplicates-skipped-kinds.yaml old mode 100755 new mode 100644 diff --git a/fixtures/duplicates-with-namespace-default.yaml b/fixtures/duplicates-with-namespace-default.yaml old mode 100755 new mode 100644 diff --git a/fixtures/duplicates-with-namespace.yaml b/fixtures/duplicates-with-namespace.yaml old mode 100755 new mode 100644 diff --git a/fixtures/duplicates.yaml b/fixtures/duplicates.yaml old mode 100755 new mode 100644 diff --git a/fixtures/extra_property.yaml b/fixtures/extra_property.yaml old mode 100755 new mode 100644 diff --git a/fixtures/folder/multi_valid.yaml b/fixtures/folder/multi_valid.yaml new file mode 100644 index 0000000..a336388 --- /dev/null +++ b/fixtures/folder/multi_valid.yaml @@ -0,0 +1,181 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-master + labels: + app: redis + tier: backend + role: master +spec: + ports: + # the port that this service should serve on + - port: 6379 + targetPort: 6379 + selector: + app: redis + tier: backend + role: master +--- +apiVersion: v1 +kind: ReplicationController +metadata: + name: redis-master + # these labels can be applied automatically + # from the labels in the pod template if not set + labels: + app: redis + role: master + tier: backend +spec: + # this replicas value is default + # modify it according to your case + replicas: 1 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # app: guestbook + # role: master + # tier: backend + template: + metadata: + labels: + app: redis + role: master + tier: backend + spec: + containers: + - name: master + image: redis + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-slave + labels: + app: redis + tier: backend + role: slave +spec: + ports: + # the port that this service should serve on + - port: 6379 + selector: + app: redis + tier: backend + role: slave +--- +apiVersion: v1 +kind: ReplicationController +metadata: + name: redis-slave + # these labels can be applied automatically + # from the labels in the pod template if not set + labels: + app: redis + role: slave + tier: backend +spec: + # this replicas value is default + # modify it according to your case + replicas: 2 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # app: guestbook + # role: slave + # tier: backend + template: + metadata: + labels: + app: redis + role: slave + tier: backend + spec: + containers: + - name: slave + image: gcr.io/google_samples/gb-redisslave:v1 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access an environment variable to find the master + # service's host, comment out the 'value: dns' line above, and + # uncomment the line below. + # value: env + ports: + - containerPort: 6379 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend + labels: + app: guestbook + tier: frontend +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + # type: LoadBalancer + ports: + # the port that this service should serve on + - port: 80 + selector: + app: guestbook + tier: frontend +--- +apiVersion: v1 +kind: ReplicationController +metadata: + name: frontend + # these labels can be applied automatically + # from the labels in the pod template if not set + labels: + app: guestbook + tier: frontend +spec: + # this replicas value is default + # modify it according to your case + replicas: 3 + # selector can be applied automatically + # from the labels in the pod template if not set + # selector: + # app: guestbook + # tier: frontend + template: + metadata: + labels: + app: guestbook + tier: frontend + spec: + containers: + - name: php-redis + image: gcr.io/google_samples/gb-frontend:v3 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access environment variables to find service host + # info, comment out the 'value: dns' line above, and uncomment the + # line below. + # value: env + ports: + - containerPort: 80 +--- +--- +# an empty resource with comments +--- diff --git a/fixtures/folder/valid.yaml b/fixtures/folder/valid.yaml new file mode 100644 index 0000000..07c350e --- /dev/null +++ b/fixtures/folder/valid.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: "bob" +spec: + replicas: 2 + selector: + app: nginx + template: + metadata: + name: nginx + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 diff --git a/fixtures/full_domain_group.yaml b/fixtures/full_domain_group.yaml old mode 100755 new mode 100644 diff --git a/fixtures/int_or_string.yaml b/fixtures/int_or_string.yaml old mode 100755 new mode 100644 diff --git a/fixtures/invalid.yaml b/fixtures/invalid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/list_invalid.yaml b/fixtures/list_invalid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/list_valid.yaml b/fixtures/list_valid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/missing_kind.yaml b/fixtures/missing_kind.yaml old mode 100755 new mode 100644 diff --git a/fixtures/missing_kind_value.yaml b/fixtures/missing_kind_value.yaml old mode 100755 new mode 100644 diff --git a/fixtures/multi_invalid.yaml b/fixtures/multi_invalid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/multi_invalid_resources.yaml b/fixtures/multi_invalid_resources.yaml old mode 100755 new mode 100644 diff --git a/fixtures/multi_valid.yaml b/fixtures/multi_valid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/multi_valid_source.yaml b/fixtures/multi_valid_source.yaml old mode 100755 new mode 100644 diff --git a/fixtures/null_array.yaml b/fixtures/null_array.yaml old mode 100755 new mode 100644 diff --git a/fixtures/null_string.yaml b/fixtures/null_string.yaml old mode 100755 new mode 100644 diff --git a/fixtures/quantity.yaml b/fixtures/quantity.yaml old mode 100755 new mode 100644 diff --git a/fixtures/same-kind-different-api.yaml b/fixtures/same-kind-different-api.yaml old mode 100755 new mode 100644 diff --git a/fixtures/same-object-different-namespace-default.yaml b/fixtures/same-object-different-namespace-default.yaml old mode 100755 new mode 100644 diff --git a/fixtures/same-object-different-namespace.yaml b/fixtures/same-object-different-namespace.yaml old mode 100755 new mode 100644 diff --git a/fixtures/test_crd.yaml b/fixtures/test_crd.yaml old mode 100755 new mode 100644 diff --git a/fixtures/unconventional_keys.yaml b/fixtures/unconventional_keys.yaml old mode 100755 new mode 100644 diff --git a/fixtures/valid.json b/fixtures/valid.json old mode 100755 new mode 100644 diff --git a/fixtures/valid.yaml b/fixtures/valid.yaml old mode 100755 new mode 100644 diff --git a/fixtures/valid_version.yaml b/fixtures/valid_version.yaml old mode 100755 new mode 100644