From 781246882e3d7d7f340fa8b8b9f9be96fa427780 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sat, 18 Nov 2023 17:58:43 +0100 Subject: [PATCH 1/2] openapi2jsonschema.py now correctly fails if no FILE is passed --- scripts/acceptance.bats | 7 +++++++ scripts/openapi2jsonschema.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/acceptance.bats b/scripts/acceptance.bats index c210d45e..4398c4e9 100644 --- a/scripts/acceptance.bats +++ b/scripts/acceptance.bats @@ -72,3 +72,10 @@ setup() { run diff prometheus_v1.json ./fixtures/prometheus_v1-denyRootAdditionalProperties.json [ "$status" -eq 0 ] } + +@test "Should output an error if no file is passed" { + run ./openapi2jsonschema.py + [ "$status" -eq 1 ] + [ "${lines[0]}" == 'Missing FILE parameter.' ] + [ "${lines[1]}" == 'Usage: ./openapi2jsonschema.py [FILE]' ] +} diff --git a/scripts/openapi2jsonschema.py b/scripts/openapi2jsonschema.py index 9d981b45..6cda017e 100755 --- a/scripts/openapi2jsonschema.py +++ b/scripts/openapi2jsonschema.py @@ -122,8 +122,8 @@ def construct_value(load, node): if __name__ == "__main__": - if len(sys.argv) == 0: - print("missing file") + if len(sys.argv) < 2: + print('Missing FILE parameter.\nUsage: %s [FILE]' % sys.argv[0]) exit(1) for crdFile in sys.argv[1:]: From e46a359dc817d3c6d4d927341559392d27f056d1 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sat, 18 Nov 2023 18:06:06 +0100 Subject: [PATCH 2/2] Update acceptance tests --- acceptance.bats | 8 ++--- fixtures/valid.json | 74 +++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/acceptance.bats b/acceptance.bats index ca49c6fb..a9d3bcd9 100755 --- a/acceptance.bats +++ b/acceptance.bats @@ -36,7 +36,7 @@ resetCacheFolder() { } @test "Pass when parsing a valid Kubernetes config JSON file" { - run bin/kubeconform -kubernetes-version 1.17.1 -summary fixtures/valid.json + run bin/kubeconform -kubernetes-version 1.20.0 -summary fixtures/valid.json [ "$status" -eq 0 ] [ "$output" = "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0" ] } @@ -134,17 +134,17 @@ resetCacheFolder() { } @test "Fail when parsing a config with additional properties and strict set" { - run bin/kubeconform -strict -kubernetes-version 1.16.0 fixtures/extra_property.yaml + run bin/kubeconform -strict -kubernetes-version 1.20.0 fixtures/extra_property.yaml [ "$status" -eq 1 ] } @test "Fail when parsing a config with duplicate properties and strict set" { - run bin/kubeconform -strict -kubernetes-version 1.16.0 fixtures/duplicate_property.yaml + run bin/kubeconform -strict -kubernetes-version 1.20.0 fixtures/duplicate_property.yaml [ "$status" -eq 1 ] } @test "Pass when parsing a config with duplicate properties and strict NOT set" { - run bin/kubeconform -kubernetes-version 1.16.0 fixtures/duplicate_property.yaml + run bin/kubeconform -kubernetes-version 1.20.0 fixtures/duplicate_property.yaml [ "$status" -eq 0 ] } diff --git a/fixtures/valid.json b/fixtures/valid.json index deb3101d..e7a5dcb7 100644 --- a/fixtures/valid.json +++ b/fixtures/valid.json @@ -1,46 +1,34 @@ { - "apiVersion": "apps/v1beta1", - "kind": "Deployment", - "metadata": { - "name": "nginx-deployment", - "namespace": "default" - }, - "spec": { - "replicas": 2, - "template": { - "spec": { - "affinity": { }, - "containers": [ - { - "args": [ ], - "command": [ ], - "env": [ ], - "envFrom": [ ], - "image": "nginx:1.7.9", - "lifecycle": { }, - "livenessProbe": { }, - "name": "nginx", - "ports": [ - { - "containerPort": 80, - "name": "http" - } - ], - "readinessProbe": { }, - "resources": { }, - "securityContext": { }, - "volumeMounts": [ ] - } - ], - "hostMappings": [ ], - "imagePullSecrets": [ ], - "initContainers": [ ], - "nodeSelector": { }, - "securityContext": { }, - "tolerations": [ ], - "volumes": [ ] - } + "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 + } + ] + } + ] } - }, - "status": { } + } + } }