Skip to content

Commit

Permalink
Dockerizing integration tests (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
qube authored and freignat91 committed Nov 22, 2016
1 parent 475231b commit b59728b
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 240 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -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"]
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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})
Expand All @@ -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))

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
45 changes: 8 additions & 37 deletions api/server/server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
29 changes: 14 additions & 15 deletions api/state/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package state
import (
"context"
"fmt"
"github.com/appcelerator/amp/api/runtime"
"github.com/appcelerator/amp/data/storage"
"path"
)
Expand All @@ -25,55 +24,55 @@ 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
}
return state == expected, nil
}

// 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)
}
8 changes: 4 additions & 4 deletions cmd/amp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
76 changes: 6 additions & 70 deletions cmd/amp/platform_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit b59728b

Please sign in to comment.