2014-01-13 16:21:34 -05:00
|
|
|
package dockerpush
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-03-13 00:30:13 -04:00
|
|
|
"github.com/mitchellh/packer/builder/docker"
|
2014-01-13 16:21:34 -05:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2014-03-13 00:30:13 -04:00
|
|
|
"github.com/mitchellh/packer/post-processor/docker-import"
|
2014-01-13 16:21:34 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPP(t *testing.T) *PostProcessor {
|
|
|
|
var p PostProcessor
|
|
|
|
if err := p.Configure(testConfig()); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &p
|
|
|
|
}
|
|
|
|
|
|
|
|
func testUi() *packer.BasicUi {
|
|
|
|
return &packer.BasicUi{
|
|
|
|
Reader: new(bytes.Buffer),
|
|
|
|
Writer: new(bytes.Buffer),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
|
|
|
|
var _ packer.PostProcessor = new(PostProcessor)
|
|
|
|
}
|
2014-03-13 00:30:13 -04:00
|
|
|
|
|
|
|
func TestPostProcessor_PostProcess(t *testing.T) {
|
|
|
|
driver := &docker.MockDriver{}
|
|
|
|
p := &PostProcessor{Driver: driver}
|
|
|
|
artifact := &packer.MockArtifact{
|
|
|
|
BuilderIdValue: dockerimport.BuilderId,
|
2014-04-26 14:12:43 -04:00
|
|
|
IdValue: "foo/bar",
|
2014-03-13 00:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
result, keep, err := p.PostProcess(testUi(), artifact)
|
|
|
|
if result != nil {
|
|
|
|
t.Fatal("should be nil")
|
|
|
|
}
|
|
|
|
if keep {
|
|
|
|
t.Fatal("should not keep")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !driver.PushCalled {
|
|
|
|
t.Fatal("should call push")
|
|
|
|
}
|
|
|
|
if driver.PushName != "foo/bar" {
|
|
|
|
t.Fatal("bad name")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_PostProcess_portInName(t *testing.T) {
|
|
|
|
driver := &docker.MockDriver{}
|
|
|
|
p := &PostProcessor{Driver: driver}
|
|
|
|
artifact := &packer.MockArtifact{
|
|
|
|
BuilderIdValue: dockerimport.BuilderId,
|
2014-04-26 14:12:43 -04:00
|
|
|
IdValue: "localhost:5000/foo/bar",
|
2014-03-13 00:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
result, keep, err := p.PostProcess(testUi(), artifact)
|
|
|
|
if result != nil {
|
|
|
|
t.Fatal("should be nil")
|
|
|
|
}
|
|
|
|
if keep {
|
|
|
|
t.Fatal("should not keep")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !driver.PushCalled {
|
|
|
|
t.Fatal("should call push")
|
|
|
|
}
|
|
|
|
if driver.PushName != "localhost:5000/foo/bar" {
|
|
|
|
t.Fatal("bad name")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_PostProcess_tags(t *testing.T) {
|
|
|
|
driver := &docker.MockDriver{}
|
|
|
|
p := &PostProcessor{Driver: driver}
|
|
|
|
artifact := &packer.MockArtifact{
|
|
|
|
BuilderIdValue: dockerimport.BuilderId,
|
2014-04-26 14:12:43 -04:00
|
|
|
IdValue: "hashicorp/ubuntu:precise",
|
2014-03-13 00:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
result, keep, err := p.PostProcess(testUi(), artifact)
|
|
|
|
if result != nil {
|
|
|
|
t.Fatal("should be nil")
|
|
|
|
}
|
|
|
|
if keep {
|
|
|
|
t.Fatal("should not keep")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !driver.PushCalled {
|
|
|
|
t.Fatal("should call push")
|
|
|
|
}
|
|
|
|
if driver.PushName != "hashicorp/ubuntu" {
|
|
|
|
t.Fatalf("bad name: %s", driver.PushName)
|
|
|
|
}
|
|
|
|
}
|