Skip to content

Commit

Permalink
test: add test file for validate.lua #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed Jan 6, 2023
1 parent a6b6cb7 commit 87338d8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/kustomize/test_data/validate/fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
22 changes: 22 additions & 0 deletions tests/kustomize/test_data/validate/pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
19 changes: 19 additions & 0 deletions tests/kustomize/test_validate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local eq = MiniTest.expect.equality

local validate = require("kustomize.validate")

local want = {
"tests/kustomize/test_data/validate/fail.yaml - Deployment nginx-deployment is invalid: For field (root): Additional property labels is not allowed",
}

describe("validate", function()
it("valid Kubernetes deployment", function()
local out = validate.run_validation("tests/kustomize/test_data/validate/pass.yaml")
eq(out, {})
end)

it("invalid Kubernetes deployment", function()
local out = validate.run_validation("tests/kustomize/test_data/validate/fail.yaml")
eq(out, want)
end)
end)

0 comments on commit 87338d8

Please sign in to comment.