75 lines
1.4 KiB
Go
75 lines
1.4 KiB
Go
package resource
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"fmt"
|
|
"log"
|
|
"testing"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var TempDir string
|
|
|
|
func TestMain(m *testing.M) {
|
|
var err error
|
|
TempDir, err = os.MkdirTemp("", "testresourcefile")
|
|
if err != nil || TempDir == "" {
|
|
log.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(TempDir)
|
|
|
|
rc := m.Run()
|
|
|
|
os.Exit(rc)
|
|
}
|
|
|
|
func TestYamlLoadDecl(t *testing.T) {
|
|
|
|
file := filepath.Join(TempDir, "fooread.txt")
|
|
|
|
resourceAttributes := make(map[string]any)
|
|
decl := fmt.Sprintf(`
|
|
path: "%s"
|
|
owner: "nobody"
|
|
group: "nobody"
|
|
mode: "0600"
|
|
content: |-
|
|
test line 1
|
|
test line 2
|
|
`, file)
|
|
|
|
e := YamlLoadDecl(decl, &resourceAttributes)
|
|
assert.Equal(t, nil, e)
|
|
|
|
assert.Equal(t, "nobody", resourceAttributes["group"])
|
|
}
|
|
|
|
func TestNewResourceDeclaration(t *testing.T) {
|
|
resourceDeclaration := NewDeclaration()
|
|
assert.NotEqual(t, nil, resourceDeclaration)
|
|
}
|
|
|
|
func TestNewResourceDeclarationType(t *testing.T) {
|
|
file := filepath.Join(TempDir, "fooread.txt")
|
|
|
|
decl := fmt.Sprintf(`
|
|
type: file
|
|
attributes:
|
|
path: "%s"
|
|
owner: "nobody"
|
|
group: "nobody"
|
|
mode: "0600"
|
|
content: |-
|
|
test line 1
|
|
test line 2
|
|
`, file)
|
|
|
|
resourceDeclaration := NewDeclaration()
|
|
assert.NotEqual(t, nil, resourceDeclaration)
|
|
|
|
resourceDeclaration.LoadDecl(decl)
|
|
assert.Equal(t, "file", resourceDeclaration.Type)
|
|
assert.NotEqual(t, nil, resourceDeclaration.Attributes)
|
|
}
|