// 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)
}

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)
}
