github.com/epicpaas/deis@v1.0.2-0.20141114233758-6bbccb748f60/router/tests/router_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 TestRouter(t *testing.T) {
    14  	var err error
    15  	setkeys := []string{
    16  		"/deis/controller/host",
    17  		"/deis/controller/port",
    18  		"/deis/builder/host",
    19  		"/deis/builder/port",
    20  		"/deis/store/gateway/host",
    21  		"/deis/store/gateway/port",
    22  	}
    23  	setdir := []string{
    24  		"/deis/controller",
    25  		"/deis/router",
    26  		"/deis/database",
    27  		"/deis/services",
    28  		"/deis/builder",
    29  		"/deis/domains",
    30  		"/deis/store",
    31  	}
    32  	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
    33  	etcdName := "deis-etcd-" + tag
    34  	cli, stdout, stdoutPipe := dockercli.NewClient()
    35  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    36  	defer cli.CmdRm("-f", etcdName)
    37  	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
    38  	etcdutils.PublishEtcd(t, handler)
    39  	host, port := utils.HostAddress(), utils.RandomPort()
    40  	fmt.Printf("--- Run deis/router:%s at %s:%s\n", tag, host, port)
    41  	name := "deis-router-" + tag
    42  	go func() {
    43  		_ = cli.CmdRm("-f", name)
    44  		err = dockercli.RunContainer(cli,
    45  			"--name", name,
    46  			"--rm",
    47  			"-p", port+":80",
    48  			"-p", utils.RandomPort()+":2222",
    49  			"-e", "EXTERNAL_PORT="+port,
    50  			"-e", "HOST="+host,
    51  			"-e", "ETCD_PORT="+etcdPort,
    52  			"deis/router:"+tag)
    53  	}()
    54  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-router running")
    55  	if err != nil {
    56  		t.Fatal(err)
    57  	}
    58  	// FIXME: nginx needs a couple seconds to wake up here
    59  	// FIXME: Wait until etcd keys are published
    60  	time.Sleep(5000 * time.Millisecond)
    61  	dockercli.DeisServiceTest(t, name, port, "http")
    62  	etcdutils.VerifyEtcdValue(t, "/deis/router/gzip", "on", etcdPort)
    63  	etcdutils.VerifyEtcdValue(t,
    64  		"/deis/router/hosts/"+host,
    65  		fmt.Sprintf("%s:%s", host, port),
    66  		etcdPort)
    67  	_ = cli.CmdRm("-f", name)
    68  }