jx/internal/resource/command_test.go

59 lines
940 B
Go
Raw Normal View History

2024-04-05 17:22:17 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
_ "fmt"
"github.com/stretchr/testify/assert"
_ "os"
_ "strings"
"testing"
)
func TestNewCommand(t *testing.T) {
c := NewCommand()
assert.NotNil(t, c)
}
func TestCommandLoad(t *testing.T) {
c := NewCommand()
assert.NotNil(t, c)
decl := `
path: find
args:
2024-04-05 20:21:36 +00:00
- "{{ .Path }}"
2024-04-05 17:22:17 +00:00
`
2024-04-05 19:46:16 +00:00
assert.Nil(t, c.LoadDecl(decl))
2024-04-05 17:22:17 +00:00
assert.Equal(t, "find", c.Path)
}
func TestCommandTemplate(t *testing.T) {
c := NewCommand()
assert.NotNil(t, c)
decl := `
path: find
args:
- "{{ .Path }}"
`
2024-04-05 19:46:16 +00:00
assert.Nil(t, c.LoadDecl(decl))
2024-04-05 17:22:17 +00:00
assert.Equal(t, "find", c.Path)
assert.Equal(t, 1, len(c.Args))
f := NewFile()
f.Path = "./"
args, templateErr := c.Template(f)
assert.Nil(t, templateErr)
assert.Equal(t, 1, len(args))
assert.Equal(t, "./", string(args[0]))
out, err := c.Execute(f)
assert.Nil(t, err)
assert.Greater(t, len(out), 0)
}