github.com/amrnt/deis@v1.3.1/registry/tests/registry_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/mock"
    11  	"github.com/deis/deis/tests/utils"
    12  )
    13  
    14  func TestRegistry(t *testing.T) {
    15  	var err error
    16  	setkeys := []string{
    17  		"/deis/cache/host",
    18  		"/deis/cache/port",
    19  		"/deis/store/gateway/host",
    20  		"/deis/store/gateway/port",
    21  		"/deis/store/gateway/accessKey",
    22  		"/deis/store/gateway/secretKey",
    23  	}
    24  	setdir := []string{
    25  		"/deis/cache",
    26  		"/deis/store",
    27  	}
    28  	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
    29  	etcdName := "deis-etcd-" + tag
    30  	cli, stdout, stdoutPipe := dockercli.NewClient()
    31  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    32  	defer cli.CmdRm("-f", etcdName)
    33  	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
    34  	etcdutils.PublishEtcd(t, handler)
    35  
    36  	// run mock ceph containers
    37  	cephName := "deis-ceph-" + tag
    38  	mock.RunMockCeph(t, cephName, cli, etcdPort)
    39  	defer cli.CmdRm("-f", "-v", cephName+"-monitor")
    40  	defer cli.CmdRm("-f", "-v", cephName+"-daemon")
    41  	defer cli.CmdRm("-f", cephName+"-metadata")
    42  	defer cli.CmdRm("-f", cephName+"-gateway")
    43  
    44  	host, port := utils.HostAddress(), utils.RandomPort()
    45  	fmt.Printf("--- Run deis/registry:%s at %s:%s\n", tag, host, port)
    46  	name := "deis-registry-" + tag
    47  	defer cli.CmdRm("-f", name)
    48  	go func() {
    49  		_ = cli.CmdRm("-f", name)
    50  		err = dockercli.RunContainer(cli,
    51  			"--name", name,
    52  			"--rm",
    53  			"-p", port+":5000",
    54  			"-e", "EXTERNAL_PORT="+port,
    55  			"-e", "HOST="+host,
    56  			"-e", "ETCD_PORT="+etcdPort,
    57  			"deis/registry:"+tag)
    58  	}()
    59  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Booting")
    60  	if err != nil {
    61  		t.Fatal(err)
    62  	}
    63  	// FIXME: Wait until etcd keys are published
    64  	time.Sleep(5000 * time.Millisecond)
    65  	dockercli.DeisServiceTest(t, name, port, "http")
    66  	etcdutils.VerifyEtcdValue(t, "/deis/registry/host", host, etcdPort)
    67  	etcdutils.VerifyEtcdValue(t, "/deis/registry/port", port, etcdPort)
    68  }