jx/internal/resource/declaration_test.go
Matthew Rich e695278d0c
All checks were successful
Declarative Tests / test (push) Successful in 48s
go fmt
2024-03-25 13:31:06 -07:00

76 lines
1.7 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"fmt"
"github.com/stretchr/testify/assert"
_ "log"
_ "os"
"path/filepath"
"testing"
)
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)
}
func TestDeclarationNewResource(t *testing.T) {
resourceDeclaration := NewDeclaration()
assert.NotNil(t, resourceDeclaration)
errNewUnknownResource := resourceDeclaration.NewResource()
assert.ErrorIs(t, errNewUnknownResource, ErrUnknownResourceType)
resourceDeclaration.Type = "file"
errNewFileResource := resourceDeclaration.NewResource()
assert.Nil(t, errNewFileResource)
//assert.NotNil(t, resourceDeclaration.Implementation)
assert.NotNil(t, resourceDeclaration.Attributes)
}