2020-12-14 10:29:58 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2020-12-14 10:29:58 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFmt(t *testing.T) {
|
|
|
|
s := &strings.Builder{}
|
|
|
|
ui := &packersdk.BasicUi{
|
|
|
|
Writer: s,
|
|
|
|
}
|
|
|
|
c := &FormatCommand{
|
|
|
|
Meta: testMeta(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui = ui
|
|
|
|
|
|
|
|
args := []string{"-check=true", filepath.Join(testFixture("fmt"), "formatted.pkr.hcl")}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
fatalCommand(t, c.Meta)
|
|
|
|
}
|
|
|
|
expected := ""
|
|
|
|
assert.Equal(t, expected, strings.TrimSpace(s.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFmt_unformattedPKRVarsTemplate(t *testing.T) {
|
|
|
|
c := &FormatCommand{
|
|
|
|
Meta: testMeta(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{"-check=true", filepath.Join(testFixture("fmt"), "unformatted.pkrvars.hcl")}
|
|
|
|
if code := c.Run(args); code != 3 {
|
|
|
|
fatalCommand(t, c.Meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFmt_unfomattedTemlateDirectory(t *testing.T) {
|
|
|
|
c := &FormatCommand{
|
|
|
|
Meta: testMeta(t),
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{"-check=true", filepath.Join(testFixture("fmt"), "")}
|
|
|
|
|
|
|
|
if code := c.Run(args); code != 3 {
|
|
|
|
fatalCommand(t, c.Meta)
|
|
|
|
}
|
|
|
|
}
|