Add 'helm lint' unit tests for extra schemas

Signed-off-by: Andy Caldwell <andycaldwell@microsoft.com>
pull/12553/head
Andy Caldwell 1 year ago
parent 12521f32fe
commit 666fa0996b
No known key found for this signature in database
GPG Key ID: D4204541AC1D228D

@ -46,11 +46,24 @@ const testSchema = `
"password": {
"description": "Your password",
"type": "string"
},
"extraData": {
"$ref": "http://example.com/helm/definitions/extraData"
}
}
}
`
const extraSchema = `
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "helm values extra data schema",
"$id": "http://example.com/helm/definitions/extraData",
"type": "string"
}
`
func TestValidateValuesYamlNotDirectory(t *testing.T) {
_ = os.Mkdir(nonExistingValuesFilePath, os.ModePerm)
defer os.Remove(nonExistingValuesFilePath)
@ -136,6 +149,17 @@ func TestValidateValuesFile(t *testing.T) {
yaml: "username: admin\npassword:",
overrides: map[string]interface{}{"username": "anotherUser", "password": "swordfish"},
},
{
name: "include extra data",
yaml: "username: admin\npassword: swordfish\nextraData: extra",
overrides: map[string]interface{}{},
},
{
name: "extra data invalid",
yaml: "username: admin\npassword: swordfish\nextraData: 1234",
overrides: map[string]interface{}{},
errorMessage: "Expected: string, given: integer",
},
}
for _, tt := range tests {
@ -165,5 +189,13 @@ func createTestingSchema(t *testing.T, dir string) string {
if err := os.WriteFile(schemafile, []byte(testSchema), 0700); err != nil {
t.Fatalf("Failed to write schema to tmpdir: %s", err)
}
extraSchemaDir := filepath.Join(dir, "schemas")
if err := os.MkdirAll(extraSchemaDir, 0700); err != nil {
t.Fatalf("Failed to create extra schema dir: %s", err)
}
extraSchemaFile := filepath.Join(extraSchemaDir, "extraData.schema.json")
if err := os.WriteFile(extraSchemaFile, []byte(extraSchema), 0700); err != nil {
t.Fatalf("Failed to write extra schema to tmpdir: %s", err)
}
return schemafile
}

Loading…
Cancel
Save