40 lines
724 B
Go
40 lines
724 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package resource
|
|
|
|
import (
|
|
_ "fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
_ "log"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewYAMLDecoder(t *testing.T) {
|
|
e := NewYAMLDecoder(strings.NewReader(""))
|
|
assert.NotNil(t, e)
|
|
}
|
|
|
|
func TestNewDecoderDecodeJSON(t *testing.T) {
|
|
decl := `{
|
|
"name": "testuser",
|
|
"uid": 12001,
|
|
"group": "12001",
|
|
"home": "/home/testuser",
|
|
"state": "present"
|
|
}`
|
|
|
|
jsonReader := strings.NewReader(decl)
|
|
user := NewUser()
|
|
|
|
e := NewJSONDecoder(jsonReader)
|
|
assert.NotNil(t, e)
|
|
docErr := e.Decode(user)
|
|
assert.Nil(t, docErr)
|
|
|
|
s := NewSchema(user.Type())
|
|
|
|
validateErr := s.Validate(decl)
|
|
assert.Nil(t, validateErr)
|
|
}
|