github.com/mboersma/deis@v1.13.4/database/tests/database_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 TestDatabase(t *testing.T) {
    15  	var err error
    16  	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
    17  	imageName := utils.ImagePrefix() + "database" + ":" + tag
    18  	cli, stdout, stdoutPipe := dockercli.NewClient()
    19  
    20  	// start etcd container
    21  	etcdName := "deis-etcd-" + tag
    22  	dockercli.RunTestEtcd(t, etcdName, etcdPort)
    23  	defer cli.CmdRm("-f", etcdName)
    24  
    25  	// run mock ceph containers
    26  	cephName := "deis-ceph-" + tag
    27  	mock.RunMockCeph(t, cephName, cli, etcdPort)
    28  	defer cli.CmdRm("-f", cephName)
    29  
    30  	// run database container
    31  	host, port := utils.HostAddress(), utils.RandomPort()
    32  	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)
    33  	name := "deis-database-" + tag
    34  	defer cli.CmdRm("-f", name)
    35  	go func() {
    36  		_ = cli.CmdRm("-f", name)
    37  		err = dockercli.RunContainer(cli,
    38  			"--name", name,
    39  			"--rm",
    40  			"-p", port+":5432",
    41  			"-e", "EXTERNAL_PORT="+port,
    42  			"-e", "HOST="+host,
    43  			"-e", "ETCD_PORT="+etcdPort,
    44  			imageName)
    45  	}()
    46  	dockercli.PrintToStdout(t, stdout, stdoutPipe, "database: postgres is running...")
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	// FIXME: Wait until etcd keys are published
    51  	time.Sleep(5000 * time.Millisecond)
    52  	dockercli.DeisServiceTest(t, name, port, "tcp")
    53  	etcdutils.VerifyEtcdValue(t, "/deis/database/host", host, etcdPort)
    54  	etcdutils.VerifyEtcdValue(t, "/deis/database/port", port, etcdPort)
    55  }