diff --git a/.travis.yml b/.travis.yml index 45421ba97..fad8c054a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,13 +18,11 @@ install: - amp platform start script: - - make install - make test after_success: - - if [ "$TRAVIS_BRANCH" == "master" and "$TRAVIS_PULL_REQUEST" != "false" ]; then + - if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && timeout 120 ./shrink.sh latest && timeout 30 docker push appcelerator/amp:latest fi - diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e300ea35..a7b0b4578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.4.0 + +### Tests + +* Dockerized integration tests [#479](https://github.com/appcelerator/amp/pull/479) + + ## 0.2.2 (2016-10-25) ### Platform diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 000000000..3859a6dcf --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,8 @@ +# appclerator/protoc is based on alpine and includes latest go and protoc +FROM appcelerator/protoc +RUN echo "@community http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories +RUN apk --no-cache add make bash git docker@community +WORKDIR /go/src/github.com/appcelerator/amp +COPY . /go/src/github.com/appcelerator/amp +ENTRYPOINT [] +CMD [ "make", "docker-integration-test"] diff --git a/Makefile b/Makefile index fd27af9d2..26b5e439d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all clean build build-cli build-cli-linux build-cli-darwin build-cli-windows build-server build-server-linux build-server-darwin build-server-windows dist-linux dist-darwin dist-windows dist build-agent build-log-worker install install-server install-cli install-agent install-log-worker fmt simplify check version build-image run -.PHONY: test +.PHONY: test test-unit test-cli test-integration docker-integration-test SHELL := /bin/bash BASEDIR := $(shell echo $${PWD}) @@ -20,8 +20,9 @@ EXCLUDE_FILES_FILTER := -not -path './vendor/*' -not -path './.git/*' -not -path EXCLUDE_DIRS_FILTER := $(EXCLUDE_FILES_FILTER) -not -path '.' -not -path './vendor' -not -path './.git' -not -path './.glide' # for tests -UNIT_TEST_PACKAGES := $(shell find . -type f -name '*_test.go' -not -path './tests/*' $(EXCLUDE_DIRS_FILTER) -exec dirname {} \; | sort -u) -INTEGRATION_TEST_PACKAGES := $(shell find ./tests -type f -name '*_test.go' $(EXCLUDE_DIRS_FILTER) -exec dirname {} \; | sort -u) +UNIT_TEST_PACKAGES := $(shell find . -type f -name '*_test.go' -not -path './tests/*' $(EXCLUDE_DIRS_FILTER) -exec dirname {} \; | sort -u) +CLI_TEST_PACKAGES := $(shell find ./tests/cli -type f -name '*_test.go' $(EXCLUDE_DIRS_FILTER) -exec dirname {} \; | sort -u) +INTEGRATION_TEST_PACKAGES := $(shell find ./tests/integration -type f -name '*_test.go' $(EXCLUDE_DIRS_FILTER) -exec dirname {} \; | sort -u) DIRS = $(shell find . -type d $(EXCLUDE_DIRS_FILTER)) @@ -158,14 +159,14 @@ dist-darwin: build-cli-darwin build-server-darwin @rm -f dist/Darwin/x86_64/amp-$(VERSION).tgz @mkdir -p dist/Darwin/x86_64 @tar czf dist/Darwin/x86_64/amp-$(VERSION).tgz $(CLI) $(SERVER) - + dist-windows: build-cli-windows build-server-windows @rm -f dist/Windows/x86_64/amp-$(VERSION).zip @mkdir -p dist/Windows/x86_64 @zip -q dist/Windows/x86_64/amp-$(VERSION).zip $(CLI).exe $(SERVER).exe - + dist: dist-linux dist-darwin dist-windows - + proto: $(PROTOFILES) @go run hack/proto.go @@ -196,17 +197,34 @@ build-image: run: build-image @CID=$(shell docker run --net=host -d --name $(SERVER) $(IMAGE)) && echo $${CID} +test-cli: + @for pkg in $(CLI_TEST_PACKAGES) ; do \ + go test $$pkg ; \ + done + test-unit: @for pkg in $(UNIT_TEST_PACKAGES) ; do \ go test $$pkg ; \ done test-integration: + @docker service rm amp-integration-test 2> /dev/null || true + @docker build -f Dockerfile.test -t appcelerator/amp-integration-test . + @docker service create --network amp-infra --name amp-integration-test --restart-condition none appcelerator/amp-integration-test + @containerid=""; \ + while [[ $${containerid} == "" ]] ; do \ + containerid=`docker ps -qf 'name=amp-integration'`; \ + sleep 1 ; \ + done; \ + docker logs -f $$containerid; \ + exit `docker inspect --format='{{.State.ExitCode}}' $$containerid` + +docker-integration-test: @for pkg in $(INTEGRATION_TEST_PACKAGES) ; do \ go test $$pkg ; \ done -test: test-unit test-integration +test: test-unit test-integration test-cli cover: echo "mode: count" > coverage-all.out diff --git a/api/server/server_utils.go b/api/server/server_utils.go index 8ccff7bb8..9d3b820f4 100644 --- a/api/server/server_utils.go +++ b/api/server/server_utils.go @@ -3,25 +3,19 @@ package server import ( "os" "strings" - - "google.golang.org/grpc" - "log" - "time" ) const ( defaultPort = ":50101" - etcdDefaultEndpoints = "http://127.0.0.1:2379" - serverAddress = "127.0.0.1" + defaultPort - elasticsearchDefaultURL = "http://127.0.0.1:9200" - natsDefaultURL = "nats://127.0.0.1:4222" - influxDefaultURL = "http://127.0.0.1:8086" + etcdDefaultEndpoints = "http://etcd:2379" + elasticsearchDefaultURL = "http://elasticsearch:9200" + natsDefaultURL = "nats://nats:4222" + influxDefaultURL = "http://influxdb:8086" dockerDefaultURL = "unix:///var/run/docker.sock" dockerDefaultVersion = "1.24" ) var ( - config Config port string etcdEndpoints string elasticsearchURL string @@ -31,7 +25,9 @@ var ( dockerVersion string ) -func parseEnv() { +// ConfigFromEnv returns configuration from environment +func ConfigFromEnv() Config { + config := Config{} port = os.Getenv("port") if port == "" { port = defaultPort @@ -70,30 +66,5 @@ func parseEnv() { config.InfluxURL = influxURL config.DockerURL = dockerURL config.DockerVersion = dockerVersion -} - -// StartTestServer start a server for test -func StartTestServer() (Config, *grpc.ClientConn) { - parseEnv() - - go Start(config) - - // Wait for swarm to be ready - log.Println("Waiting for swarm to be ready") - if err := initDependencies(config); err != nil { - log.Panicln("Dependencies are not ready", err) - } - - // Connect to amplifier - log.Println("Connecting to amplifier") - conn, err := grpc.Dial(serverAddress, - grpc.WithInsecure(), - grpc.WithBlock(), - grpc.WithTimeout(60*time.Second)) - if err != nil { - log.Panicln("Cannot connect to amplifier", err) - } - log.Println("Connected to amplifier") - - return config, conn + return config } diff --git a/api/state/machine.go b/api/state/machine.go index 98db5cb09..c0fd193c4 100644 --- a/api/state/machine.go +++ b/api/state/machine.go @@ -3,7 +3,6 @@ package state import ( "context" "fmt" - "github.com/appcelerator/amp/api/runtime" "github.com/appcelerator/amp/data/storage" "path" ) @@ -25,39 +24,39 @@ func NewMachine(ruleSet RuleSet, store storage.Interface) Machine { } // canTransition return whether or not you can transition between states -func (s *Machine) canTransition(from string, to string) bool { - return s.ruleSet[from][to] +func (m *Machine) canTransition(from string, to string) bool { + return m.ruleSet[from][to] } // GetState get state -func (s *Machine) GetState(id string) (string, error) { +func (m *Machine) GetState(id string) (string, error) { state := &State{} - if err := runtime.Store.Get(context.Background(), path.Join(statesRootKey, id), state, true); err != nil { + if err := m.store.Get(context.Background(), path.Join(statesRootKey, id), state, true); err != nil { return "", err } return state.Value, nil } // TransitionTo transitionTo -func (s *Machine) TransitionTo(id string, to string) error { - current, err := s.GetState(id) +func (m *Machine) TransitionTo(id string, to string) error { + current, err := m.GetState(id) if err != nil { return err } - if !s.canTransition(current, to) { + if !m.canTransition(current, to) { return fmt.Errorf("Cannot transition from state %s to state %s", current, to) } expect := &State{Value: current} update := &State{Value: to} - if err = runtime.Store.CompareAndSet(context.Background(), path.Join(statesRootKey, id), expect, update); err != nil { + if err = m.store.CompareAndSet(context.Background(), path.Join(statesRootKey, id), expect, update); err != nil { return fmt.Errorf("Cannot transition from state %s to state %s", current, to) } return nil } // Is is -func (s *Machine) Is(id string, expected string) (bool, error) { - state, err := s.GetState(id) +func (m *Machine) Is(id string, expected string) (bool, error) { + state, err := m.GetState(id) if err != nil { return false, err } @@ -65,15 +64,15 @@ func (s *Machine) Is(id string, expected string) (bool, error) { } // CreateState createstate -func (s *Machine) CreateState(id string, initial string) error { +func (m *Machine) CreateState(id string, initial string) error { state := &State{Value: initial} - if err := runtime.Store.Create(context.Background(), path.Join(statesRootKey, id), state, nil, 0); err != nil { + if err := m.store.Create(context.Background(), path.Join(statesRootKey, id), state, nil, 0); err != nil { return err } return nil } // DeleteState deleteState -func (s *Machine) DeleteState(id string) error { - return runtime.Store.Delete(context.Background(), path.Join(statesRootKey, id), false, nil) +func (m *Machine) DeleteState(id string) error { + return m.store.Delete(context.Background(), path.Join(statesRootKey, id), false, nil) } diff --git a/cmd/amp/main.go b/cmd/amp/main.go index 66201ac09..2b77903db 100644 --- a/cmd/amp/main.go +++ b/cmd/amp/main.go @@ -20,10 +20,10 @@ var ( AMP *client.AMP // Config is used by command implementations to access the computed client configuration. - Config = &client.Configuration{} - configFile string - verbose bool - serverAddr string + Config = &client.Configuration{} + configFile string + verbose bool + serverAddr string listVersion = true // RootCmd is the base command for the CLI. diff --git a/cmd/amp/platform_infrastructure.go b/cmd/amp/platform_infrastructure.go index 35d6aa8d3..9b7e25513 100644 --- a/cmd/amp/platform_infrastructure.go +++ b/cmd/amp/platform_infrastructure.go @@ -81,19 +81,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { Constraints: nil, }, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 2379, - PublishedPort: 2379, - }, - { - TargetPort: 2380, - PublishedPort: 2380, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, @@ -206,19 +194,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { Constraints: nil, }, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 4222, - PublishedPort: 4222, - }, - { - TargetPort: 8222, - PublishedPort: 8222, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, @@ -248,19 +224,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { Constraints: nil, }, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 8086, - PublishedPort: 8086, - }, - { - TargetPort: 8083, - PublishedPort: 8083, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, @@ -290,19 +254,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { Constraints: nil, }, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 9200, - PublishedPort: 9200, - }, - { - TargetPort: 9300, - PublishedPort: 9300, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, @@ -371,15 +323,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { }, Placement: nil, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 5000, - PublishedPort: 5000, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, @@ -440,15 +384,7 @@ func getAMPInfrastructureStack(m *ampManager) *ampStack { }, Placement: nil, }, - EndpointSpec: &swarm.EndpointSpec{ - Mode: swarm.ResolutionModeVIP, - Ports: []swarm.PortConfig{ - { - TargetPort: 3000, - PublishedPort: 6001, - }, - }, - }, + EndpointSpec: nil, Networks: []swarm.NetworkAttachmentConfig{ { Target: infraPrivateNetwork, diff --git a/docker-compose.es.yml b/docker-compose.es.yml deleted file mode 100644 index b5d817698..000000000 --- a/docker-compose.es.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: "2" - -services: - elasticsearch: - image: appcelerator/elasticsearch-amp:latest - ports: - - "9200:9200" - - "9300:9300" diff --git a/docker-compose.production.yml b/docker-compose.production.yml deleted file mode 100644 index 2d3920b7b..000000000 --- a/docker-compose.production.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: "2" - -services: - amp: - image: appcelerator/amp - build: . diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index 115acd8e2..000000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: "2" - -services: - sut: - image: appcelerator/sut - build: . - command: ["make", "test"] - environment: - endpoints: http://etcd:2379 - influxhost: influxdb - elasticsearchURL: http://elasticsearch:9200 - etcd: - image: quay.io/coreos/etcd - command: [ - "etcd", - "-name", "etcd0", - "-advertise-client-urls", "http://etcd:2379", - "-listen-client-urls", "http://0.0.0.0:2379", - "-initial-advertise-peer-urls", "http://etcd:2380", - "-initial-cluster-token", "etcd-cluster-1", - "-initial-cluster", "etcd0=http://etcd:2380", - "-initial-cluster-state", "new" - ] - influxdb: - image: appcelerator/influxdb:influxdb-1.0 - environment: - FORCE_HOSTNAME: auto - PRE_CREATE_DB: telegraf - CONFIG_ARCHIVE_URL: "https://github.com/appcelerator/amp-config/archive/0.2.0.tar.gz" - elasticsearch: - image: appcelerator/elasticsearch-amp - zookeeper: - image: appcelerator/zookeeper:latest - log-worker: - image: appcelerator/amp-log-worker:latest - restart: "always" - agent: - image: appcelerator/amp-agent:latest - privileged: true - volumes: - - /var/run/docker.sock:/var/run/docker.sock diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 304f5b880..cc202710e 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -2,7 +2,6 @@ package cli_test import ( "fmt" - "os" "os/exec" "sync" @@ -19,7 +18,6 @@ import ( "text/template" "time" - "github.com/appcelerator/amp/api/server" "gopkg.in/yaml.v2" ) @@ -51,12 +49,6 @@ var ( wg sync.WaitGroup ) -//start amplifier -func TestMain(m *testing.M) { - server.StartTestServer() - os.Exit(m.Run()) -} - //read, parse and execute test commands func TestCmds(t *testing.T) { suiteTimeout = "1m" diff --git a/tests/data/influx/influx_test.go b/tests/integration/data/influx/influx_test.go similarity index 96% rename from tests/data/influx/influx_test.go rename to tests/integration/data/influx/influx_test.go index 049fe80ca..d1c395d4a 100644 --- a/tests/data/influx/influx_test.go +++ b/tests/integration/data/influx/influx_test.go @@ -35,7 +35,7 @@ func TestQuery(t *testing.T) { func influxInit() { host := os.Getenv("influxhost") - cstr := "http://127.0.0.1:8086" + cstr := "http://influxdb:8086" if host != "" { cstr = "http://" + host + ":8086" } diff --git a/tests/data/storage/etcd/store_test.go b/tests/integration/data/storage/etcd/store_test.go similarity index 94% rename from tests/data/storage/etcd/store_test.go rename to tests/integration/data/storage/etcd/store_test.go index 35ffedfcf..1850ff6ba 100644 --- a/tests/data/storage/etcd/store_test.go +++ b/tests/integration/data/storage/etcd/store_test.go @@ -9,13 +9,13 @@ import ( "testing" "time" - "github.com/appcelerator/amp/api/runtime" - "github.com/appcelerator/amp/api/server" "github.com/appcelerator/amp/api/state" "github.com/appcelerator/amp/data/storage" + "github.com/appcelerator/amp/data/storage/etcd" "github.com/docker/docker/pkg/testutil/assert" "github.com/golang/protobuf/proto" "golang.org/x/net/context" + "strings" ) const ( @@ -35,8 +35,13 @@ func TestMain(m *testing.M) { log.SetFlags(log.Lshortfile) log.SetPrefix("test: ") - server.StartTestServer() - store = runtime.Store + etcdEndpoints := []string{"http://etcd:2379"} + log.Printf("connecting to etcd at %s", strings.Join(etcdEndpoints, ",")) + store = etcd.New(etcdEndpoints, "amp") + if err := store.Connect(defTimeout); err != nil { + log.Panicln("Unable to connect to etcd on: %s\n%v", etcdEndpoints, err) + } + log.Printf("connected to etcd at %v", strings.Join(store.Endpoints(), ",")) os.Exit(m.Run()) } diff --git a/tests/data/storage/etcd/store_test.pb.go b/tests/integration/data/storage/etcd/store_test.pb.go similarity index 54% rename from tests/data/storage/etcd/store_test.pb.go rename to tests/integration/data/storage/etcd/store_test.pb.go index 7a3cc955d..7862897f7 100644 --- a/tests/data/storage/etcd/store_test.pb.go +++ b/tests/integration/data/storage/etcd/store_test.pb.go @@ -1,12 +1,12 @@ // Code generated by protoc-gen-go. -// source: github.com/appcelerator/amp/tests/data/storage/etcd/store_test.proto +// source: github.com/appcelerator/amp/tests/integration/data/storage/etcd/store_test.proto // DO NOT EDIT! /* Package etcd is a generated protocol buffer package. It is generated from these files: - github.com/appcelerator/amp/tests/data/storage/etcd/store_test.proto + github.com/appcelerator/amp/tests/integration/data/storage/etcd/store_test.proto It has these top-level messages: TestMessage @@ -43,18 +43,19 @@ func init() { } func init() { - proto.RegisterFile("github.com/appcelerator/amp/tests/data/storage/etcd/store_test.proto", fileDescriptor0) + proto.RegisterFile("github.com/appcelerator/amp/tests/integration/data/storage/etcd/store_test.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 139 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x1c, 0xcb, 0x31, 0x0b, 0xc2, 0x30, - 0x14, 0x04, 0x60, 0x1a, 0x8a, 0x60, 0x04, 0x87, 0x4c, 0x1d, 0xc5, 0xc9, 0xa9, 0x0f, 0xf1, 0x2f, - 0xb8, 0xba, 0x88, 0xbb, 0xbc, 0x26, 0x47, 0x0c, 0x18, 0x13, 0xf2, 0x9e, 0xff, 0xbf, 0x34, 0xdb, - 0xdd, 0x77, 0x9c, 0xbd, 0xc7, 0xa4, 0x9f, 0xff, 0x32, 0xfb, 0x92, 0x89, 0x6b, 0xf5, 0xf8, 0xa2, - 0xb1, 0x96, 0x46, 0x9c, 0x2b, 0x29, 0x44, 0x85, 0x02, 0x2b, 0x93, 0x68, 0x69, 0x1c, 0x41, 0x50, - 0x1f, 0x7a, 0xc1, 0x7b, 0x5b, 0xe7, 0xda, 0x8a, 0x16, 0x37, 0x6e, 0x7c, 0xbe, 0xda, 0xc3, 0x0b, - 0xa2, 0x0f, 0x88, 0x70, 0x84, 0x3b, 0x5a, 0x93, 0xc2, 0x34, 0x9c, 0x86, 0xcb, 0xfe, 0x69, 0x52, - 0x70, 0xce, 0x8e, 0x3f, 0xce, 0x98, 0x4c, 0x97, 0x9e, 0x97, 0x5d, 0xff, 0xdf, 0xd6, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xe7, 0x7a, 0xda, 0xe8, 0x87, 0x00, 0x00, 0x00, + // 145 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x1c, 0xcb, 0xc1, 0x0a, 0xc2, 0x30, + 0x10, 0x04, 0x50, 0x5a, 0x8a, 0x60, 0x04, 0x0f, 0x39, 0xf5, 0x28, 0x9e, 0x3c, 0x75, 0x11, 0xbf, + 0x43, 0x10, 0xf1, 0x2e, 0xdb, 0x66, 0x89, 0x01, 0x9b, 0x0d, 0xd9, 0xf1, 0xff, 0xa5, 0xb9, 0xcd, + 0x3c, 0x66, 0xdc, 0x23, 0x26, 0x7c, 0x7e, 0xf3, 0xb4, 0xe8, 0x4a, 0x5c, 0xca, 0x22, 0x5f, 0xa9, + 0x0c, 0xad, 0xc4, 0x6b, 0x21, 0x88, 0xc1, 0x28, 0x65, 0x48, 0xac, 0x8c, 0xa4, 0x99, 0x02, 0x83, + 0xc9, 0xa0, 0x95, 0xa3, 0x90, 0x60, 0x09, 0xad, 0xc8, 0x7b, 0x5b, 0x4e, 0xa5, 0x2a, 0xd4, 0x0f, + 0x1b, 0x9f, 0xaf, 0xee, 0xf0, 0x12, 0xc3, 0x5d, 0xcc, 0x38, 0x8a, 0x3f, 0xba, 0x3e, 0x85, 0xb1, + 0x3b, 0x75, 0x97, 0xfd, 0xb3, 0x4f, 0xc1, 0x7b, 0x37, 0x64, 0x5e, 0x65, 0xec, 0x9b, 0xb4, 0x3c, + 0xef, 0xda, 0xff, 0xf6, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x3c, 0x0f, 0x7d, 0xf0, 0x93, 0x00, 0x00, + 0x00, } diff --git a/tests/data/storage/etcd/store_test.proto b/tests/integration/data/storage/etcd/store_test.proto similarity index 100% rename from tests/data/storage/etcd/store_test.proto rename to tests/integration/data/storage/etcd/store_test.proto diff --git a/tests/data/storage/etcd/store_test.swagger.json b/tests/integration/data/storage/etcd/store_test.swagger.json similarity index 71% rename from tests/data/storage/etcd/store_test.swagger.json rename to tests/integration/data/storage/etcd/store_test.swagger.json index 62e0e8dc8..b21e75746 100644 --- a/tests/data/storage/etcd/store_test.swagger.json +++ b/tests/integration/data/storage/etcd/store_test.swagger.json @@ -1,7 +1,7 @@ { "swagger": "2.0", "info": { - "title": "github.com/appcelerator/amp/tests/data/storage/etcd/store_test.proto", + "title": "github.com/appcelerator/amp/tests/integration/data/storage/etcd/store_test.proto", "version": "version not set" }, "schemes": [ diff --git a/tests/rpc/logs_test.go b/tests/integration/rpc/logs_test.go similarity index 100% rename from tests/rpc/logs_test.go rename to tests/integration/rpc/logs_test.go diff --git a/tests/rpc/main_test.go b/tests/integration/rpc/main_test.go similarity index 58% rename from tests/rpc/main_test.go rename to tests/integration/rpc/main_test.go index 9cd46eef1..dc9fc4b80 100644 --- a/tests/rpc/main_test.go +++ b/tests/integration/rpc/main_test.go @@ -16,6 +16,10 @@ import ( "github.com/appcelerator/amp/api/rpc/stack" "github.com/appcelerator/amp/api/rpc/stats" "github.com/appcelerator/amp/api/rpc/topic" + "github.com/appcelerator/amp/data/storage" + "github.com/appcelerator/amp/data/storage/etcd" + "google.golang.org/grpc" + "time" ) var ( @@ -26,35 +30,38 @@ var ( topicClient topic.TopicClient serviceClient service.ServiceClient logsClient logs.LogsClient + store storage.Interface ) func TestMain(m *testing.M) { + // Get configuration + config = server.ConfigFromEnv() - //init server and context - conf, conn := server.StartTestServer() - config = conf - //config = server.GetConfig() - /* - log.Printf("Connecting to amplifier %s:%s\n", config.ServerAddress, config.ServerPort) - conn, err := grpc.Dial(config.ServerAddress+":"+config.ServerPort, - grpc.WithInsecure(), - grpc.WithBlock(), - grpc.WithTimeout(60*time.Second)) - if err != nil { - log.Panicln("Cannot connect to amplifier", err) - os.Exit(1) - } - */ + // Connect to amplifier + log.Println("Connecting to amplifier") + conn, err := grpc.Dial("amplifier:50101", + grpc.WithInsecure(), + grpc.WithBlock(), + grpc.WithTimeout(60*time.Second)) + if err != nil { + log.Panicln("Cannot connect to amplifier", err) + } log.Println("Connected to amplifier") + + store = etcd.New(config.EtcdEndpoints, "amp") + if err := store.Connect(5 * time.Second); err != nil { + log.Panicf("Unable to connect to etcd on: %s\n%v", config.EtcdEndpoints, err) + } + ctx = context.Background() - //init package clients + // init package clients statsClient = stats.NewStatsClient(conn) stackClient = stack.NewStackServiceClient(conn) topicClient = topic.NewTopicClient(conn) serviceClient = service.NewServiceClient(conn) logsClient = logs.NewLogsClient(conn) - //start tests + // start tests os.Exit(m.Run()) } diff --git a/tests/rpc/service_test.go b/tests/integration/rpc/service_test.go similarity index 100% rename from tests/rpc/service_test.go rename to tests/integration/rpc/service_test.go diff --git a/tests/rpc/stack_test.go b/tests/integration/rpc/stack_test.go similarity index 94% rename from tests/rpc/stack_test.go rename to tests/integration/rpc/stack_test.go index 9228f454f..6043cc081 100644 --- a/tests/rpc/stack_test.go +++ b/tests/integration/rpc/stack_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/appcelerator/amp/api/rpc/stack" - "github.com/appcelerator/amp/api/runtime" "github.com/appcelerator/amp/api/state" "github.com/docker/docker/pkg/stringid" "github.com/stretchr/testify/assert" @@ -108,7 +107,7 @@ func TestStackShouldManageStackLifeCycleSuccessfully(t *testing.T) { } func TestTransitionsFromStopped(t *testing.T) { - machine := state.NewMachine(stack.StackRuleSet, runtime.Store) + machine := state.NewMachine(stack.StackRuleSet, store) id := stringid.GenerateNonCryptoID() machine.CreateState(id, stack.StackState_Stopped.String()) @@ -129,7 +128,7 @@ func TestTransitionsFromStopped(t *testing.T) { } func TestTransitionsFromStarting(t *testing.T) { - machine := state.NewMachine(stack.StackRuleSet, runtime.Store) + machine := state.NewMachine(stack.StackRuleSet, store) id := stringid.GenerateNonCryptoID() machine.CreateState(id, stack.StackState_Starting.String()) @@ -150,7 +149,7 @@ func TestTransitionsFromStarting(t *testing.T) { } func TestTransitionsFromRunning(t *testing.T) { - machine := state.NewMachine(stack.StackRuleSet, runtime.Store) + machine := state.NewMachine(stack.StackRuleSet, store) id := stringid.GenerateNonCryptoID() machine.CreateState(id, stack.StackState_Running.String()) @@ -171,7 +170,7 @@ func TestTransitionsFromRunning(t *testing.T) { } func TestTransitionsFromRedeploying(t *testing.T) { - machine := state.NewMachine(stack.StackRuleSet, runtime.Store) + machine := state.NewMachine(stack.StackRuleSet, store) id := stringid.GenerateNonCryptoID() machine.CreateState(id, stack.StackState_Redeploying.String()) diff --git a/tests/rpc/stats_test.go b/tests/integration/rpc/stats_test.go similarity index 100% rename from tests/rpc/stats_test.go rename to tests/integration/rpc/stats_test.go diff --git a/tests/rpc/topic_test.go b/tests/integration/rpc/topic_test.go similarity index 100% rename from tests/rpc/topic_test.go rename to tests/integration/rpc/topic_test.go