jx/internal/resource/decoder_test.go

57 lines
1017 B
Go
Raw Normal View History

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
2024-04-05 17:22:17 +00:00
_ "fmt"
"github.com/stretchr/testify/assert"
2024-04-05 17:22:17 +00:00
_ "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)
}
2024-04-05 17:22:17 +00:00
func TestNewJSONStringDecoder(t *testing.T) {
decl := `{
"name": "testuser",
"uid": 12001,
"group": "12001",
"home": "/home/testuser",
"state": "present"
}`
user := NewUser()
e := NewJSONStringDecoder(decl)
assert.NotNil(t, e)
docErr := e.Decode(user)
assert.Nil(t, docErr)
}