github.com/ahjdzx/deis@v1.1.1/cache/tests/cache_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 TestCache(t *testing.T) {
    14  	var err error
    15  	tag := utils.BuildTag()
    16  	etcdPort := utils.RandomPort()
    17  	etcdName := "deis-etcd-" + tag
    18  	cli, stdout, stdoutPipe := dockercli.NewClient()
    19  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    20  	defer cli.CmdRm("-f", etcdName)
    21  	host, port := utils.HostAddress(), utils.RandomPort()
    22  	fmt.Printf("--- Run deis/cache:%s at %s:%s\n", tag, host, port)
    23  	name := "deis-cache-" + tag
    24  	defer cli.CmdRm("-f", name)
    25  	go func() {
    26  		_ = cli.CmdRm("-f", name)
    27  		err = dockercli.RunContainer(cli,
    28  			"--name", name,
    29  			"--rm",
    30  			"-p", port+":6379",
    31  			"-e", "EXTERNAL_PORT="+port,
    32  			"-e", "HOST="+host,
    33  			"-e", "ETCD_PORT="+etcdPort,
    34  			"deis/cache:"+tag)
    35  	}()
    36  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "started")
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	// FIXME: Wait until etcd keys are published
    41  	time.Sleep(5000 * time.Millisecond)
    42  	dockercli.DeisServiceTest(t, name, port, "tcp")
    43  	etcdutils.VerifyEtcdValue(t, "/deis/cache/host", host, etcdPort)
    44  	etcdutils.VerifyEtcdValue(t, "/deis/cache/port", port, etcdPort)
    45  }