2024-07-01 21:54:18 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewSchema(t *testing.T) {
|
|
|
|
s := NewSchema("document")
|
|
|
|
assert.NotEqual(t, nil, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSchemaValidateJSON(t *testing.T) {
|
|
|
|
// ctx := context.Background()
|
|
|
|
s := NewSchema("block")
|
|
|
|
assert.NotNil(t, s)
|
|
|
|
|
|
|
|
assert.Nil(t, s.ValidateSchema())
|
|
|
|
|
|
|
|
configBlockYaml := `
|
|
|
|
type: "generic"
|
|
|
|
name: "foo"
|
|
|
|
values:
|
|
|
|
bar: quuz
|
|
|
|
`
|
|
|
|
|
2024-09-27 00:20:51 +00:00
|
|
|
testConfig := NewGeneric[any]()
|
|
|
|
|
|
|
|
e := testConfig.LoadYAML(configBlockYaml)
|
2024-07-01 21:54:18 +00:00
|
|
|
assert.Nil(t, e)
|
|
|
|
|
|
|
|
jsonDoc, jsonErr := json.Marshal(testConfig)
|
|
|
|
assert.Nil(t, jsonErr)
|
|
|
|
|
|
|
|
schemaErr := s.Validate(string(jsonDoc))
|
|
|
|
assert.Nil(t, schemaErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSchemaValidateSchema(t *testing.T) {
|
2024-09-27 00:20:51 +00:00
|
|
|
s := NewSchema("document")
|
|
|
|
assert.NotNil(t, s)
|
2024-07-01 21:54:18 +00:00
|
|
|
|
|
|
|
assert.Nil(t, s.ValidateSchema())
|
|
|
|
}
|