Skip to content

Commit

Permalink
Using Terratest for Testing the Examples (#47)
Browse files Browse the repository at this point in the history
Using Terratest for testing the examples
  • Loading branch information
nolte authored Jul 31, 2020
1 parent 0ec428e commit 837a369
Show file tree
Hide file tree
Showing 47 changed files with 958 additions and 349 deletions.
5 changes: 0 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/terraform-doc /usr/local/bin/terraform-doc
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/shellcheck /usr/local/bin/shellcheck

RUN curl -sSL -k https://github.com/bats-core/bats-core/archive/v${BATS_VERSION}.tar.gz -o /tmp/bats.tgz \
&& tar -zxf /tmp/bats.tgz -C /tmp \
&& /bin/bash /tmp/bats-core-${BATS_VERSION}/install.sh /usr/local

RUN curl -sSL -k https://github.com/bflad/tfproviderdocs/releases/download/v0.6.0/tfproviderdocs_0.6.0_linux_amd64.tar.gz -o /tmp/tfproviderdocs.tgz \
&& tar -zxf /tmp/tfproviderdocs.tgz -C /tmp \
&& mv /tmp/tfproviderdocs /usr/local/bin/


RUN apk add --update-cache \
nodejs npm \
&& rm -rf /var/cache/apk/*
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"spikespaz.vscode-smoothtype", // smooth cursor animation
"vscode-icons-team.vscode-icons",
// markdown
"jebbs.markdown-extended",
"bierner.github-markdown-preview",
"HashiCorp.terraform",
"ms-kubernetes-tools.kind-vscode",
Expand Down
96 changes: 0 additions & 96 deletions .github/workflows/cicd-acc.yml

This file was deleted.

194 changes: 193 additions & 1 deletion .github/workflows/cicd-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
&& chmod +x $HOME/bin/swagger
echo "::add-path::$HOME/bin"
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: install go stuff
run: |
go get -v \
Expand All @@ -40,6 +46,192 @@ jobs:
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
- name: test provider
- name: compile the provider
run: |
make build
- name: Upload terraform provider
uses: actions/upload-artifact@v2
with:
name: provider
path: bin/*
acc:
name: Acception Tests
runs-on: ubuntu-latest
strategy:
matrix:
harbor_deployments:
- helm_chart_version: 1.4.0
harbor_path: "/api/v2.0"
- helm_chart_version: 1.4.1
harbor_path: "/api/v2.0"
# TODO: https://github.com/nolte/terraform-provider-harbor/issues/40
#- helm_chart_version: 1.3.2
# harbor_path: "/api"
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

- name: Get dependencies
run: |
SWAGGER_VERSION=v0.23.0
mkdir -p $HOME/bin
curl -Lo $HOME/bin/swagger https://github.com/go-swagger/go-swagger/releases/download/${SWAGGER_VERSION}/swagger_linux_amd64 \
&& chmod +x $HOME/bin/swagger
echo "::add-path::$HOME/bin"
- name: install go stuff
run: |
go get -v \
github.com/magefile/mage \
github.com/evanphx/json-patch/cmd/json-patch
echo "::add-path::$(go env GOPATH)/bin"
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
- name: Generate Api Client from Swagger Spac
run: |
make generate
# https://github.com/engineerd/setup-kind
- uses: engineerd/[email protected]
with:
skipClusterCreation: true

- name: Starting the Kind Cluster
run: |
./scripts/tst-00-prepare-kind.sh
- name: configure kind kubeconfig
run: |
kind export kubeconfig
kubectl cluster-info
kubectl get pods -n kube-system
NODEDNSNAME=$(kubectl get nodes -ojson | jq '.items[0].status.addresses[0].address' -r | sed 's/\./-/g')
echo "::set-env name=INGRESS_DOMAIN::${NODEDNSNAME}.sslip.io"
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
- name: install helm3
run: |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- name: install harbor
run: |
./scripts/tst-01-prepare-harbor.sh ${INGRESS_DOMAIN} "${{ matrix.harbor_deployments.helm_chart_version }}"
- name: Starting the Acc
run: |
./scripts/tst-15-execute-go-acc.sh "${{ matrix.harbor_deployments.harbor_path }}"
- name: remove the kind cluster
if: ${{ always() }}
run: |
kind delete cluster
acc_terratest:
name: acc-terratest
runs-on: ubuntu-latest
needs: build
#env:
# TF_LOG: TRACE
strategy:
# Workarround, otherwithe the the different matrix jobs faild.
# max-parallel: 1
fail-fast: false
matrix:
terraform_version:
# - 0.11.14 Out of Support
- 0.12.25
- 0.12.29
# - 0.13.0-rc1 # required changes at the cicd structure
harbor_deployments:
- helm_chart_version: 1.4.0
harbor_path: "/api/v2.0"
- helm_chart_version: 1.4.1
harbor_path: "/api/v2.0"
# TODO: https://github.com/nolte/terraform-provider-harbor/issues/40
- helm_chart_version: 1.3.2
harbor_path: "/api"
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

- name: Download terraform provider binary
uses: actions/download-artifact@v2
with:
name: provider
path: bin

- name: install the provider to local terrafomd.d folder
run: |
ls -all bin/*
mkdir -p ~/.terraform.d/plugins/linux_amd64/
tar -C ~/.terraform.d/plugins/linux_amd64/ -xvf ./bin/terraform-provider-harbor_v0.1.0_linux_amd64.tar.gz
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ matrix.terraform_version }}

# https://github.com/engineerd/setup-kind
- uses: engineerd/[email protected]
with:
skipClusterCreation: true

- name: Starting the Kind Cluster
run: |
./scripts/tst-00-prepare-kind.sh
- name: configure kind kubeconfig
run: |
kind export kubeconfig
kubectl cluster-info
kubectl get pods -n kube-system
NODEDNSNAME=$(kubectl get nodes -ojson | jq '.items[0].status.addresses[0].address' -r | sed 's/\./-/g')
echo "::set-env name=INGRESS_DOMAIN::${NODEDNSNAME}.sslip.io"
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
- name: install helm3
run: |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- name: install harbor
run: |
./scripts/tst-01-prepare-harbor.sh ${INGRESS_DOMAIN} "${{ matrix.harbor_deployments.helm_chart_version }}"
#- name: install harbor
# run: |
# echo "::set-env name=INGRESS_DOMAIN::harbor.${NODEDNSNAME}.sslip.io"
- name: Wait some Time
run: |
sleep 30
- name: Starting the Acc
run: |
./scripts/tst-15-execute-classic-acc.sh "${{ matrix.harbor_deployments.harbor_path }}"
- name: read harbor logs core
if: ${{ failure() }}
run: |
kubectl logs -l component=core -n harbor --tail=-1
- name: read harbor logs jobservice
if: ${{ failure() }}
run: |
kubectl logs -l component=jobservice -n harbor --tail=-1
- name: remove the kind cluster
if: ${{ always() }}
run: |
kind delete cluster
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GO := go

# generate harbor cient files from swagger config
define install_provider
mkdir -p ~/.terraform.d/plugins/linux_amd64/
tar -zxf bin/terraform-provider-harbor_*_linux_amd64.tar.gz -C ~/.terraform.d/plugins/linux_amd64/
chmod +x ~/.terraform.d/plugins/linux_amd64/terraform-provider-harbor
endef
Expand Down Expand Up @@ -61,7 +62,7 @@ e2e_prepare:


e2e_prepare_harbor_v1:
scripts/tst-01-prepare-harbor.sh "172-17-0-1.sslip.io" "1.3.4"
scripts/tst-01-prepare-harbor.sh "172-17-0-1.sslip.io" "1.3.2"

e2e_prepare_harbor_v2:
scripts/tst-01-prepare-harbor.sh "172-17-0-1.sslip.io" "1.4.0"
Expand All @@ -83,7 +84,7 @@ e2e_test_v1:
scripts/tst-15-execute-go-acc.sh "/api"

e2e_test_classic:
bats scripts/test/bats
scripts/tst-15-execute-classic-acc.sh "/api/v2.0"

e2e_full_run: e2e_clean_cluster e2e_prepare e2e_prepare_harbor_v2 e2e_test_v2 e2e_clean_harbor e2e_prepare_harbor_v1 e2e_test_v1 e2e_clean_cluster
# e2e_prepare e2e_prepare_harbor_v1 e2e_test e2e_cleanup
Expand Down
Loading

0 comments on commit 837a369

Please sign in to comment.