Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kuziemko committed Mar 25, 2022
1 parent 3aa3042 commit 7ca8f46
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 432 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/branch-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ jobs:
run: |
make release-latest-binaries
localhub-tests:
name: Local Hub tests
local-hub-tests:
name: Local Hub integration tests
runs-on: ubuntu-latest
needs: [ entry-tests, build-app, build-tests ]
permissions:
Expand All @@ -211,11 +211,11 @@ jobs:
- name: Setup environment
run: |
. ./hack/ci/setup-env.sh
- name: Run local Hub tests
- name: Run local Hub integration tests
env:
BUILD_IMAGES: "false"
run: |
make test-localhub
make test-local-hub
integration-tests:
name: Integration tests
Expand Down Expand Up @@ -304,7 +304,7 @@ jobs:
slackNotification:
name: Slack Notification
runs-on: ubuntu-latest
needs: [ update-cluster, localhub-tests, integration-tests ]
needs: [ update-cluster, local-hub-tests, integration-tests ]
if: failure()
steps:
- name: Slack Notification
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ jobs:
path: ${{ github.workspace }}/bin/capact_linux_amd64/capact
retention-days: 1 # Default 90 days

localhub-tests:
name: Local Hub tests
local-hub-tests:
name: Local Hub integration tests
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [ push-apps, push-tests, build-cli ]
Expand All @@ -421,11 +421,11 @@ jobs:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Run local Hub tests
- name: Run local Hub integration tests
env:
BUILD_IMAGES: "false"
run: |
make test-localhub
make test-local-hub
integration-tests:
name: Integration tests
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all: generate build-all-images test-unit test-lint ## Default: generate all, bui
############

APPS = gateway k8s-engine hub-js argo-runner helm-runner cloudsql-runner populator terraform-runner argo-actions gitlab-api-runner secret-storage-backend helm-storage-backend
TESTS = e2e localhub
TESTS = e2e local-hub
INFRA = json-go-gen graphql-schema-linter jinja2 merger

build-all-tools: ## Builds the standalone binaries for all tools
Expand Down Expand Up @@ -85,7 +85,7 @@ build-test-image-e2e:
build-test-image-%:
$(eval APP := $*)
# localhub tests needs to be run sequentially
$(eval BUILD_CMD=$(if $(APP) localhub,"go test -v -c -p 1","go test -v -c"))
$(eval BUILD_CMD=$(if $(APP) local-hub,"go test -v -c -p 1","go test -v -c"))
docker build --build-arg COMPONENT=$(APP) \
--build-arg BUILD_CMD=$(BUILD_CMD) \
--build-arg SOURCE_PATH="./test/$(APP)/*_test.go" \
Expand Down Expand Up @@ -126,9 +126,9 @@ test-lint: ## Run linters on the codebase
./hack/lint.sh
.PHONY: test-lint

test-localhub:
./hack/test-localhub.sh
.PHONY: test-integration
test-local-hub:
./hack/test-local-hub.sh
.PHONY: test-local-hub

test-integration:
./hack/test-integration.sh
Expand Down
2 changes: 1 addition & 1 deletion hack/ci/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ fi
# TODO: Read components to build in automated way, e.g. from directory structure
cat <<EOT >>"$GITHUB_ENV"
APPS=name=matrix::{"include":[{"APP":"gateway"},{"APP":"k8s-engine"},{"APP":"hub-js"},{"APP":"argo-runner"},{"APP":"helm-runner"},{"APP":"populator"},{"APP":"terraform-runner"},{"APP":"argo-actions"},{"APP":"gitlab-api-runner"},{"APP":"secret-storage-backend"},{"APP":"helm-storage-backend"}]}
TESTS=name=matrix::{"include":[{"TEST":"e2e"}, {"TEST":"localhub"}]}
TESTS=name=matrix::{"include":[{"TEST":"e2e"}, {"TEST":"local-hub"}]}
INFRAS=name=matrix::{"include":[{"INFRA":"json-go-gen"},{"INFRA":"graphql-schema-linter"},{"INFRA":"jinja2"},{"INFRA":"merger"}]}
EOT
10 changes: 8 additions & 2 deletions hack/test-localhub.sh → hack/test-local-hub.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build_images() {
export DOCKER_TAG=$RANDOM
export DOCKER_REPOSITORY="local"

local make_targets=("build-test-image-localhub" "build-app-image-hub-js" "build-app-image-secret-storage-backend")
local make_targets=("build-test-image-local-hub" "build-app-image-hub-js" "build-app-image-secret-storage-backend")
for make_target in "${make_targets[@]}"
do
cd "${REPO_ROOT_DIR}" && make "${make_target}"
Expand All @@ -33,7 +33,13 @@ main() {
build_images
fi

docker-compose -f "${REPO_ROOT_DIR}/test/localhub/docker-compose.yml" up --exit-code-from tests --force-recreate
docker-compose -f "${REPO_ROOT_DIR}/test/local-hub/docker-compose.yml" up --exit-code-from tests --force-recreate
}

cleanup() {
docker-compose -f "${REPO_ROOT_DIR}/test/local-hub/docker-compose.yml" down
}

trap cleanup EXIT

main
File renamed without changes.
34 changes: 17 additions & 17 deletions test/localhub/crud_test.go → test/local-hub/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestUpdateTypeInstances(t *testing.T) {

var createdTIIDs []string

// given id1 and id2 are not locked
t.Log("given id1 and id2 are not locked")
for _, ver := range []string{"id1", "id2"} {
outID, err := cli.CreateTypeInstance(ctx, typeInstance(ver))
require.NoError(t, err)
Expand All @@ -151,7 +151,7 @@ func TestUpdateTypeInstances(t *testing.T) {
},
}

// when try to update them
t.Log("when try to update them")
updatedTI, err := cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: createdTIIDs[0],
Expand All @@ -163,28 +163,28 @@ func TestUpdateTypeInstances(t *testing.T) {
},
})

// then should success
t.Log("then should success")
require.NoError(t, err)
for _, instance := range updatedTI {
assert.Equal(t, len(instance.LatestResourceVersion.Metadata.Attributes), 1)
assert.EqualValues(t, instance.LatestResourceVersion.Metadata.Attributes[0], expUpdateTI.Attributes[0])
}

// when id1 and id2 are locked by Foo
t.Log("when id1 and id2 are locked by Foo")
expUpdateTI = &gqllocalapi.UpdateTypeInstanceInput{
Attributes: []*gqllocalapi.AttributeReferenceInput{
{Path: "cap.update.locked.by.foo", Revision: "0.0.1"},
},
}

// then should success
t.Log("then should success")
err = cli.LockTypeInstances(ctx, &gqllocalapi.LockTypeInstancesInput{
Ids: createdTIIDs,
OwnerID: fooOwnerID,
})
require.NoError(t, err)

// when update them as Foo owner
t.Log("when update them as Foo owner")
updatedTI, err = cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: createdTIIDs[0],
Expand All @@ -198,14 +198,14 @@ func TestUpdateTypeInstances(t *testing.T) {
},
})

// then should success
t.Log("then should success")
require.NoError(t, err)
for _, instance := range updatedTI {
assert.Equal(t, len(instance.LatestResourceVersion.Metadata.Attributes), 1)
assert.EqualValues(t, instance.LatestResourceVersion.Metadata.Attributes[0], expUpdateTI.Attributes[0])
}

// when update them as Bar owner
t.Log("when update them as Bar owner")
_, err = cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: createdTIIDs[0],
Expand All @@ -219,12 +219,12 @@ func TestUpdateTypeInstances(t *testing.T) {
},
})

// then should failed with error id1,id2 already locked by different owner
t.Log("then should failed with error id1,id2 already locked by different owner")
require.Error(t, err)
assert.Regexp(t, regexp.MustCompile(heredoc.Docf(`while executing mutation to update TypeInstances: All attempts fail:
#1: graphql: failed to update TypeInstances: TypeInstances with IDs %s are locked by different owner`, allPermutations(createdTIIDs))), err.Error())

// when update them without owner
t.Log("when update them without owner")
_, err = cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: createdTIIDs[0],
Expand All @@ -236,12 +236,12 @@ func TestUpdateTypeInstances(t *testing.T) {
},
})

// then should failed with error id1,id2 already locked by different owner
t.Log("then should failed with error id1,id2 already locked by different owner")
require.Error(t, err)
assert.Regexp(t, regexp.MustCompile(heredoc.Docf(`while executing mutation to update TypeInstances: All attempts fail:
#1: graphql: failed to update TypeInstances: TypeInstances with IDs %s are locked by different owner`, allPermutations(createdTIIDs))), err.Error())

// when update one property with Foo owner, and second without owner
t.Log("when update one property with Foo owner, and second without owner")
_, err = cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: createdTIIDs[0],
Expand All @@ -254,26 +254,26 @@ func TestUpdateTypeInstances(t *testing.T) {
},
})

// then should failed with error id2 already locked by different owner
t.Log("then should failed with error id2 already locked by different owner")
require.Error(t, err)
require.Equal(t, err.Error(), heredoc.Docf(`while executing mutation to update TypeInstances: All attempts fail:
#1: graphql: failed to update TypeInstances: TypeInstances with IDs "%s" are locked by different owner`, createdTIIDs[1]))

// given id3 does not exist
// when try to update it
t.Log("given id3 does not exist")
t.Log("when try to update it")
_, err = cli.UpdateTypeInstances(ctx, []gqllocalapi.UpdateTypeInstancesInput{
{
ID: "id3",
TypeInstance: expUpdateTI,
},
})

// then should failed with error id3 not found
t.Log("then should failed with error id3 not found")
require.Error(t, err)
require.Equal(t, err.Error(), heredoc.Doc(`while executing mutation to update TypeInstances: All attempts fail:
#1: graphql: failed to update TypeInstances: TypeInstances with IDs "id3" were not found`))

// then should unlock id1,id2,id3"
t.Log("then should unlock id1,id2,id3")
err = cli.UnlockTypeInstances(ctx, &gqllocalapi.UnlockTypeInstancesInput{
Ids: createdTIIDs,
OwnerID: fooOwnerID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: "3.9"
services:
tests:
image: "${DOCKER_REPOSITORY}/localhub-test:${DOCKER_TAG}"
image: "${DOCKER_REPOSITORY}/local-hub-test:${DOCKER_TAG}"
depends_on:
hubjs:
condition: service_healthy
environment:
- LOCALHUB_ADDR=http://hubjs:8080/graphql
- GRPC_SECRET_STORAGE_BACKEND_ADDR=http://backend-storage:50051
- GRPC_SECRET_STORAGE_BACKEND_ADDR=test-storage-backend:50051
hubjs:
image: "${DOCKER_REPOSITORY}/hub-js:${DOCKER_TAG}"
restart: on-failure
Expand All @@ -23,11 +23,11 @@ services:
neo4j:
condition: service_healthy
healthcheck:
test: netstat -ltn | grep -c 8080
interval: 5s
timeout: 5s
retries: 10
start_period: 60s
test: wget http://localhost:8080/healthz -O -
interval: 10s
timeout: 3s
retries: 30
start_period: 10s
neo4j:
image: "ghcr.io/capactio/neo4j:4.2.13-apoc"
restart: on-failure
Expand All @@ -38,12 +38,12 @@ services:
- NEO4J_AUTH=neo4j/okon
- NEO4JLABS_PLUGINS=["apoc"]
healthcheck:
test: wget http://localhost:7474/browser -O -
test: bash -c 'echo -n > /dev/tcp/127.0.0.1/7687'
interval: 10s
timeout: 10s
retries: 10
start_period: 40s
backend-storage:
timeout: 3s
retries: 30
start_period: 10s
test-storage-backend:
image: "${DOCKER_REPOSITORY}/secret-storage-backend:${DOCKER_TAG}"
restart: on-failure
environment:
Expand Down
Loading

0 comments on commit 7ca8f46

Please sign in to comment.