github.com/techend/deis@v1.0.1-0.20141111224634-e0eee0392b8a/builder/tests/builder_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/deis/deis/tests/dockercli"
     9  	"github.com/deis/deis/tests/etcdutils"
    10  	"github.com/deis/deis/tests/utils"
    11  )
    12  
    13  func TestBuilder(t *testing.T) {
    14  	var err error
    15  	setkeys := []string{
    16  		"/deis/registry/protocol",
    17  		"/deis/registry/host",
    18  		"/deis/registry/port",
    19  		"/deis/cache/host",
    20  		"/deis/cache/port",
    21  		"/deis/controller/protocol",
    22  		"/deis/controller/host",
    23  		"/deis/controller/port",
    24  		"/deis/controller/builderKey",
    25  	}
    26  	setdir := []string{
    27  		"/deis/controller",
    28  		"/deis/cache",
    29  		"/deis/database",
    30  		"/deis/registry",
    31  		"/deis/domains",
    32  		"/deis/services",
    33  	}
    34  	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
    35  	etcdName := "deis-etcd-" + tag
    36  	cli, stdout, stdoutPipe := dockercli.NewClient()
    37  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    38  	defer cli.CmdRm("-f", etcdName)
    39  	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
    40  	etcdutils.PublishEtcd(t, handler)
    41  	host, port := utils.HostAddress(), utils.RandomPort()
    42  	fmt.Printf("--- Run deis/builder:%s at %s:%s\n", tag, host, port)
    43  	name := "deis-builder-" + tag
    44  	defer cli.CmdRm("-f", "-v", name)
    45  	go func() {
    46  		_ = cli.CmdRm("-f", "-v", name)
    47  		err = dockercli.RunContainer(cli,
    48  			"--name", name,
    49  			"--rm",
    50  			"-p", port+":22",
    51  			"-e", "PORT=22",
    52  			"-e", "STORAGE_DRIVER=aufs",
    53  			"-e", "HOST="+host,
    54  			"-e", "ETCD_PORT="+etcdPort,
    55  			"-e", "EXTERNAL_PORT="+port,
    56  			"--privileged", "deis/builder:"+tag)
    57  	}()
    58  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-builder running")
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  	// FIXME: builder needs a few seconds to wake up here!
    63  	// FIXME: Wait until etcd keys are published
    64  	time.Sleep(5000 * time.Millisecond)
    65  	dockercli.DeisServiceTest(t, name, port, "tcp")
    66  	etcdutils.VerifyEtcdValue(t, "/deis/builder/host", host, etcdPort)
    67  	etcdutils.VerifyEtcdValue(t, "/deis/builder/port", port, etcdPort)
    68  }