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-09 08:57:42 -05:00
|
|
|
{"basic"},
|
|
|
|
{"minimal"},
|
|
|
|
{"source-name"},
|
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"))
|
2020-08-25 04:51:43 -04:00
|
|
|
p := helperCommand(t, "hcl2_upgrade", inputPath)
|
|
|
|
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
|
|
|
|
}
|