github.phpd.cn/hashicorp/packer@v1.3.2/builder/lxc/builder_test.go (about) 1 package lxc 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/hashicorp/packer/packer" 8 ) 9 10 func testConfig() map[string]interface{} { 11 return map[string]interface{}{ 12 "config_file": "builder_test.go", 13 "template_name": "debian", 14 "template_environment_vars": "SUITE=jessie", 15 } 16 } 17 18 func TestBuilder_Foo(t *testing.T) { 19 if os.Getenv("PACKER_ACC") == "" { 20 t.Skip("This test is only run with PACKER_ACC=1") 21 } 22 } 23 24 func TestBuilderPrepare_ConfigFile(t *testing.T) { 25 var b Builder 26 // Good 27 config := testConfig() 28 warnings, err := b.Prepare(config) 29 if len(warnings) > 0 { 30 t.Fatalf("bad: %#v", warnings) 31 } 32 if err != nil { 33 t.Fatalf("should not have error: %s", err) 34 } 35 36 // Bad, missing config file 37 config = testConfig() 38 delete(config, "config_file") 39 b = Builder{} 40 warnings, err = b.Prepare(config) 41 if len(warnings) > 0 { 42 t.Fatalf("bad: %#v", warnings) 43 } 44 if err == nil { 45 t.Fatalf("should have error") 46 } 47 48 } 49 50 func TestBuilder_ImplementsBuilder(t *testing.T) { 51 var raw interface{} 52 raw = &Builder{} 53 if _, ok := raw.(packer.Builder); !ok { 54 t.Fatalf("Builder should be a builder") 55 } 56 }