[lxc] add basic tests
This commit is contained in:
parent
986ac9a501
commit
9b4a7e935f
|
@ -0,0 +1,56 @@
|
|||
package lxc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"os"
|
||||
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"config_file": "builder_test.go",
|
||||
"template_name": "debian",
|
||||
"template_environment_vars": "SUITE=jessie",
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
warnings, err := b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
// Bad, missing config file
|
||||
config = testConfig()
|
||||
delete(config, "config_file")
|
||||
b = Builder{}
|
||||
warnings, err = b.Prepare(config)
|
||||
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{}
|
||||
if _, ok := raw.(packer.Builder); !ok {
|
||||
t.Fatalf("Builder should be a builder")
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type LxcAttachCommunicator struct {
|
||||
|
@ -105,7 +105,7 @@ func (c *LxcAttachCommunicator) Download(src string, w io.Writer) error {
|
|||
}
|
||||
|
||||
func (c *LxcAttachCommunicator) DownloadDir(src string, dst string, exclude []string) error {
|
||||
return fmt.Errorf("DownloadDir is not implemented for lxc")
|
||||
return fmt.Errorf("DownloadDir is not implemented for lxc")
|
||||
}
|
||||
|
||||
func (c *LxcAttachCommunicator) Execute(commandString string) (*exec.Cmd, error) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package lxc
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCommunicator_ImplementsCommunicator(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &LxcAttachCommunicator{}
|
||||
if _, ok := raw.(packer.Communicator); !ok {
|
||||
t.Fatalf("Communicator should be a communicator")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue