60 lines
1000 B
Go
60 lines
1000 B
Go
package resource
|
|
|
|
import (
|
|
"os"
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
"path/filepath"
|
|
"testing"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewDocumentLoader(t *testing.T) {
|
|
d := NewDocument()
|
|
assert.NotEqual(t, nil, d)
|
|
}
|
|
|
|
func TestDocumentLoader(t *testing.T) {
|
|
dir, err := os.MkdirTemp("", "testdocumentloader")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
|
|
file := filepath.Join(dir, "foo.txt")
|
|
|
|
document := fmt.Sprintf(`
|
|
---
|
|
resources:
|
|
- type: file
|
|
attributes:
|
|
path: "%s"
|
|
owner: "nobody"
|
|
group: "nobody"
|
|
mode: "0600"
|
|
content: |-
|
|
test line 1
|
|
test line 2
|
|
state: present
|
|
- type: user
|
|
attributes:
|
|
name: "testuser"
|
|
uid: "10022"
|
|
gid: "10022"
|
|
home: "/home/testuser"
|
|
state: present
|
|
`, file)
|
|
|
|
d := NewDocument()
|
|
assert.NotEqual(t, nil, d)
|
|
|
|
docReader := strings.NewReader(document)
|
|
|
|
e := d.Load(docReader)
|
|
assert.Equal(t, nil, e)
|
|
|
|
resources := d.Resources()
|
|
assert.Equal(t, 2, len(resources))
|
|
}
|