2020-08-25 04:51:43 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_hcl2_upgrade(t *testing.T) {
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Getwd: %v", err)
|
|
|
|
}
|
|
|
|
_ = cwd
|
|
|
|
|
|
|
|
tc := []struct {
|
|
|
|
folder string
|
2021-02-12 09:18:53 -05:00
|
|
|
flags []string
|
2020-08-25 04:51:43 -04:00
|
|
|
}{
|
2021-02-12 09:18:53 -05:00
|
|
|
{folder: "complete", flags: []string{"-with-annotations"}},
|
|
|
|
{folder: "without-annotations", flags: []string{}},
|
|
|
|
{folder: "minimal", flags: []string{"-with-annotations"}},
|
|
|
|
{folder: "source-name", flags: []string{"-with-annotations"}},
|
|
|
|
{folder: "error-cleanup-provisioner", flags: []string{"-with-annotations"}},
|
2021-02-15 11:35:03 -05:00
|
|
|
{folder: "aws-access-config", flags: []string{}},
|
2020-08-25 04:51:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tc {
|
|
|
|
t.Run(tc.folder, func(t *testing.T) {
|
2021-02-09 08:57:42 -05:00
|
|
|
inputPath := filepath.Join(testFixture("hcl2_upgrade", tc.folder, "input.json"))
|
2020-08-25 04:51:43 -04:00
|
|
|
outputPath := inputPath + ".pkr.hcl"
|
2021-02-09 08:57:42 -05:00
|
|
|
expectedPath := filepath.Join(testFixture("hcl2_upgrade", tc.folder, "expected.pkr.hcl"))
|
2021-02-12 09:18:53 -05:00
|
|
|
args := []string{"hcl2_upgrade"}
|
|
|
|
if len(tc.flags) > 0 {
|
|
|
|
args = append(args, tc.flags...)
|
|
|
|
}
|
|
|
|
args = append(args, inputPath)
|
|
|
|
p := helperCommand(t, args...)
|
2020-08-25 04:51:43 -04:00
|
|
|
bs, err := p.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%v %s", err, bs)
|
|
|
|
}
|
|
|
|
expected := mustBytes(ioutil.ReadFile(expectedPath))
|
|
|
|
actual := mustBytes(ioutil.ReadFile(outputPath))
|
|
|
|
|
|
|
|
if diff := cmp.Diff(expected, actual); diff != "" {
|
|
|
|
t.Fatalf("unexpected output: %s", diff)
|
|
|
|
}
|
|
|
|
os.Remove(outputPath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustBytes(b []byte, e error) []byte {
|
|
|
|
if e != nil {
|
|
|
|
panic(e)
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|