Merge branch 'test_ci_integration_local_code' into 'master'

Test ci integration local code

See merge request !121
This commit is contained in:
James Jeffrey
2017-07-21 16:18:48 -07:00
5 changed files with 111 additions and 54 deletions

View File

@@ -15,32 +15,6 @@ before_script:
- ln -s `pwd` "${GOPATH}/src/gitlab-odx.oracle.com/odx/"
- cd "${GOPATH}/src/gitlab-odx.oracle.com/odx/functions"
# get_deps:
# stage: deps
# script:
# - cd "${GOPATH}/src/gitlab-odx.oracle.com/odx/functions"
# - pwd
# - go get github.com/Masterminds/glide
# - glide install --strip-vendor
# - cd "${GOPATH}/src/gitlab-odx.oracle.com/odx/functions/fn"
# - pwd
# - glide install --strip-vendor
# only:
# - master
#
# load_deps:
# stage: deps
# script:
# - cd "${GOPATH}/src/gitlab-odx.oracle.com/odx/functions"
# - pwd
# - ls vendor/github.com/ > /dev/null || which glide || go get github.com/Masterminds/glide
# - ls vendor/github.com/ > /dev/null || glide install --strip-vendor
# - cd "${GOPATH}/src/gitlab-odx.oracle.com/odx/functions/fn"
# - pwd
# - ls vendor/github.com/ > /dev/null || glide install --strip-vendor
# except:
# - master
build_job:
stage: build
script:
@@ -62,15 +36,12 @@ test_job:
script:
- DOCKER_LOCATION=container_ip ./test.sh
#integration_tests:
# stage: test
# script:
# - go build -o functions-alpine
# - docker build -t funcy/functions:latest .
# - make docker-test-run-with-bolt
# - make docker-test-run-with-mysql
# - make docker-test-run-with-postgres
# - make docker-test-run-with-redis
integration_tests:
stage: test
script:
- go build -o functions-alpine
- docker build -t funcy/functions:latest .
- make docker-test-run-with-sqlite3
deploy_job:
only:

View File

@@ -2,10 +2,12 @@ set -ex
case "$1" in
"sqlite3" )
docker rm -fv func-server || echo No prev func-server container
docker run --name func-server --privileged -v /var/run/docker.sock:/var/run/docker.sock -d -e NO_PROXY -e HTTP_PROXY -e DOCKER_HOST=${DOCKER_HOST} -e LOG_LEVEL=debug -p 8080:8080 funcy/functions
sleep 1
# docker rm -fv func-server || echo No prev func-server container
#
# docker run --name func-server --privileged -v /var/run/docker.sock:/var/run/docker.sock -d -e NO_PROXY -e HTTP_PROXY -e DOCKER_HOST=${DOCKER_HOST} -e LOG_LEVEL=debug -p 8080:8080 funcy/functions
# sleep 10
# docker logs func-server
# docker inspect -f '{{.NetworkSettings.IPAddress}}' func-server
;;
"mysql" )
@@ -13,10 +15,14 @@ case "$1" in
docker rm -fv func-server || echo No prev func-server container
docker run --name func-mysql-test -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql
sleep 8
sleep 30
docker logs func-mysql-test
export MYSQL_HOST="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' func-mysql-test)"
export MYSQL_PORT=3306
docker run --name func-server --privileged -d -e NO_PROXY -e HTTP_PROXY -e DOCKER_HOST=${DOCKER_HOST} -e LOG_LEVEL=debug -e "DB_URL=mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs" -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock funcy/functions
docker logs func-server
docker inspect -f '{{.NetworkSettings.IPAddress}}' func-mysql-test
docker inspect -f '{{.NetworkSettings.IPAddress}}' func-server
;;
@@ -25,10 +31,14 @@ case "$1" in
docker rm -fv func-server || echo No prev func-server container
docker run --name func-postgres-test -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres
sleep 8
sleep 30
docker logs func-postgres-test
export POSTGRES_HOST="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' func-postgres-test)"
export POSTGRES_PORT=5432
docker run --name func-server --privileged -d -e NO_PROXY -e HTTP_PROXY -e DOCKER_HOST=${DOCKER_HOST} -e LOG_LEVEL=debug -e "DB_URL=postgres://postgres:root@${POSTGRES_HOST}:${POSTGRES_PORT}/funcs?sslmode=disable" -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock funcy/functions
docker logs func-server
docker inspect -f '{{.NetworkSettings.IPAddress}}' func-postgres-test
docker inspect -f '{{.NetworkSettings.IPAddress}}' func-server
;;
esac

View File

@@ -51,6 +51,7 @@ func CallAsync(t *testing.T, u url.URL, content io.Reader) string {
func TestRouteExecutions(t *testing.T) {
s := SetupDefaultSuite()
newRouteType := "async"
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
@@ -203,7 +204,7 @@ func TestRouteExecutions(t *testing.T) {
u.Path = path.Join(u.Path, "r", s.AppName, routePath)
callID := CallAsync(t, u, &bytes.Buffer{})
time.Sleep(7 * time.Second)
time.Sleep(15 * time.Second)
cfg := &operations.GetCallsCallLogParams{
Call: callID,

View File

@@ -0,0 +1,13 @@
package tests
import (
"os"
"testing"
)
func TestMain(m *testing.M) {
// call flag.Parse() here if TestMain uses flags
s := SetupDefaultSuite()
defer s.Cancel()
os.Exit(m.Run())
}

View File

@@ -3,21 +3,26 @@ package tests
import (
"context"
"strings"
"sync"
"testing"
"time"
"gitlab-odx.oracle.com/odx/functions/api/server"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"github.com/funcy/functions_go/client"
"github.com/funcy/functions_go/client/apps"
"github.com/funcy/functions_go/client/routes"
"github.com/funcy/functions_go/models"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"io"
"log"
"net/http"
"net/url"
"os"
"github.com/spf13/viper"
)
func Host() string {
@@ -41,16 +46,53 @@ func APIClient() *client.Functions {
// create the API client, with the transport
client := client.New(transport, strfmt.Default)
_, err := client.Version.GetVersion(nil)
if err != nil {
if Host() != "localhost:8080" {
panic("Cannot reach remote api for functions")
}
}
return client
}
var (
getServer sync.Once
)
func getServerWithCancel() (*server.Server, context.CancelFunc) {
var cancel2 context.CancelFunc
var s *server.Server
getServer.Do(func() {
ctx, cancel := context.WithCancel(context.Background())
viper.Set(server.EnvPort, "8080")
viper.Set(server.EnvAPIURL, "http://localhost:8080")
viper.Set(server.EnvLogLevel, "fatal")
timeString := time.Now().Format("2006_01_02_15_04_05")
tmpDir := os.TempDir()
tmpMq := fmt.Sprintf("%s/fn_integration_test_%s_worker_mq.db", tmpDir, timeString)
tmpDB := fmt.Sprintf("%s/fn_integration_test_%s_fn.db", tmpDir, timeString)
viper.Set(server.EnvMQURL, fmt.Sprintf("bolt://%s", tmpMq))
viper.Set(server.EnvDBURL, fmt.Sprintf("sqlite3://%s", tmpDB))
s = server.NewFromEnv(ctx)
go s.Start(ctx)
started := false
time.AfterFunc(time.Second*10, func() {
if !started {
panic("Failed to start server.")
}
})
_, err := http.Get(viper.GetString(server.EnvAPIURL) + "/version")
for err != nil {
_, err = http.Get(viper.GetString(server.EnvAPIURL) + "/version")
}
started = true
cancel2 = context.CancelFunc(func() {
cancel()
os.Remove(tmpMq)
os.Remove(tmpDB)
})
})
return s, cancel2
}
type SuiteSetup struct {
Context context.Context
Client *client.Functions
@@ -62,10 +104,11 @@ type SuiteSetup struct {
Memory int64
RouteConfig map[string]string
RouteHeaders map[string][]string
Cancel context.CancelFunc
}
func SetupDefaultSuite() *SuiteSetup {
return &SuiteSetup{
ss := &SuiteSetup{
Context: context.Background(),
Client: APIClient(),
AppName: "test-app",
@@ -75,7 +118,26 @@ func SetupDefaultSuite() *SuiteSetup {
RouteType: "async",
RouteConfig: map[string]string{},
RouteHeaders: map[string][]string{},
Cancel: func() {},
}
_, ok := ss.Client.Version.GetVersion(nil)
if ok != nil {
if Host() != "localhost:8080" {
_, ok := http.Get(fmt.Sprintf("http://%s/version", Host()))
if ok != nil {
panic("Cannot reach remote api for functions")
}
} else {
_, ok := http.Get(fmt.Sprintf("http://%s/version", Host()))
if ok != nil {
log.Println("Making functions server")
_, cancel := getServerWithCancel()
ss.Cancel = cancel
}
}
}
return ss
}
func CheckAppResponseError(t *testing.T, err error) {