Deploy sh

This commit is contained in:
James Jeffrey
2017-06-09 13:42:59 -07:00
committed by Reed Allman
parent aa170c918f
commit 79f1dab007
10 changed files with 312 additions and 170 deletions

View File

@@ -5,7 +5,9 @@ import (
"fmt"
"log"
"net/url"
"os"
"os/exec"
"strconv"
"testing"
"time"
@@ -13,16 +15,34 @@ import (
"gitlab-odx.oracle.com/odx/functions/api/datastore/internal/datastoretest"
)
const tmpRedis = "redis://%v:6301/"
const tmpRedis = "redis://%s:%d/"
var (
redisHost = func() string {
host := os.Getenv("REDIS_HOST")
if host == "" {
host = "127.0.0.1"
}
return host
}()
redisPort = func() int {
port := os.Getenv("REDIS_PORT")
if port == "" {
port = "6301"
}
p, err := strconv.Atoi(port)
if err != nil {
panic(err)
}
return p
}()
)
func prepareRedisTest(logf, fatalf func(string, ...interface{})) (func(), func()) {
fmt.Println("initializing redis for test")
tryRun(logf, "remove old redis container", exec.Command("docker", "rm", "-f", "func-redis-test"))
mustRun(fatalf, "start redis container", exec.Command("docker", "run", "--name", "func-redis-test", "-p", "6301:6379", "-d", "redis"))
timeout := time.After(20 * time.Second)
for {
c, err := redis.DialURL(fmt.Sprintf(tmpRedis, datastoretest.GetContainerHostIP()))
c, err := redis.DialURL(fmt.Sprintf(tmpRedis, redisHost, redisPort))
if err == nil {
_, err = c.Do("PING")
c.Close()
@@ -41,7 +61,7 @@ func prepareRedisTest(logf, fatalf func(string, ...interface{})) (func(), func()
fmt.Println("redis for test ready")
return func() {},
func() {
tryRun(logf, "stop redis container", exec.Command("docker", "rm", "-f", "func-redis-test"))
tryRun(logf, "stop redis container", exec.Command("docker", "rm", "-fv", "func-redis-test"))
}
}
@@ -49,7 +69,7 @@ func TestDatastore(t *testing.T) {
_, close := prepareRedisTest(t.Logf, t.Fatalf)
defer close()
u, err := url.Parse(fmt.Sprintf(tmpRedis, datastoretest.GetContainerHostIP()))
u, err := url.Parse(fmt.Sprintf(tmpRedis, redisHost, redisPort))
if err != nil {
t.Fatal("failed to parse url: ", err)
}