// 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:
- "{{ .Path }}"
`

	assert.Nil(t, c.LoadDecl(decl))
	assert.Equal(t, "find", c.Path)
}

func TestCommandTemplate(t *testing.T) {
	c := NewCommand()
	assert.NotNil(t, c)

	decl := `
path: find
args:
- "{{ .Path }}"
`

	assert.Nil(t, c.LoadDecl(decl))
	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)
}
