Skip to content

Instantly share code, notes, and snippets.

@aaron-prindle
Created February 5, 2025 19:47

Revisions

  1. aaron-prindle created this gist Feb 5, 2025.
    54 changes: 54 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # Base valid ReplicationController object (must be the SAME as in valid.yaml)
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: valid-rc
    spec:
    replicas: 1
    selector:
    app: my-app
    template:
    metadata:
    labels:
    app: my-app
    spec:
    containers:
    - name: my-container
    image: nginx:latest
    ---
    # Test Case 1: Replicas = -1 (replace)
    name: invalid replicas - -1 (replace)
    replace:
    "spec.replicas": -1 # Invalid: negative value
    expectedErrors:
    - field: spec.replicas
    type: FieldValueInvalid
    detail: must be greater than or equal to 0
    ---
    #Test Case 2: Replicas are a string not a number
    name: invalid replicas - string
    replace:
    "spec.replicas": "foo"
    expectedErrors:
    - field: spec.replicas
    type: FieldValueInvalid
    detail: "invalid type"
    ---
    # Test Case 3: Replicas = -5 (applyConfiguration)
    name: invalid replicas - -5 (applyConfiguration)
    applyConfiguration:
    spec:
    replicas: -5 # Invalid: negative value
    expectedErrors:
    - field: spec.replicas
    type: FieldValueInvalid
    detail: must be greater than or equal to 0
    ---
    # Test Case 4: Replicas = -2 (jsonPatch)
    name: invalid replicas - -2 (jsonPatch)
    jsonPatch:
    - { "op": "replace", "path": "/spec/replicas", "value": -2 } # Invalid: negative value
    expectedErrors:
    - field: spec.replicas
    type: FieldValueInvalid
    detail: must be greater than or equal to 0