2016-05-26 23:21:55 -04:00
|
|
|
package lxd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2016-05-26 23:21:55 -04:00
|
|
|
)
|
2016-05-30 19:13:59 -04:00
|
|
|
|
2016-05-26 23:21:55 -04:00
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
2016-05-30 19:57:26 -04:00
|
|
|
"output_image": "foo",
|
|
|
|
"image": "bar",
|
2016-05-26 23:21:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilder_Foo(t *testing.T) {
|
|
|
|
if os.Getenv("PACKER_ACC") == "" {
|
|
|
|
t.Skip("This test is only run with PACKER_ACC=1")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderPrepare_ConfigFile(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
// Good
|
|
|
|
config := testConfig()
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warnings, err := b.Prepare(config)
|
2016-05-26 23:21:55 -04:00
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-05-31 19:53:50 -04:00
|
|
|
// Good, remote image
|
|
|
|
config = testConfig()
|
|
|
|
config["image"] = "remote:bar"
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warnings, err = b.Prepare(config)
|
2016-05-31 19:53:50 -04:00
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Good, remote output image
|
|
|
|
config = testConfig()
|
|
|
|
config["output_image"] = "remote:foo"
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warnings, err = b.Prepare(config)
|
2016-05-31 19:53:50 -04:00
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-05-26 23:21:55 -04:00
|
|
|
// Bad, missing image name
|
|
|
|
config = testConfig()
|
|
|
|
delete(config, "image")
|
|
|
|
b = Builder{}
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warnings, err = b.Prepare(config)
|
2016-05-26 23:21:55 -04:00
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|
|
|
var raw interface{}
|
|
|
|
raw = &Builder{}
|
2020-12-01 16:42:11 -05:00
|
|
|
if _, ok := raw.(packersdk.Builder); !ok {
|
2016-05-26 23:21:55 -04:00
|
|
|
t.Fatalf("Builder should be a builder")
|
|
|
|
}
|
|
|
|
}
|