Skip to content

Commit

Permalink
Merge pull request #81 from hail-insta-org/master
Browse files Browse the repository at this point in the history
Run tests from Circle CI upon PR commits
  • Loading branch information
admintfprovider authored Apr 19, 2021
2 parents d3d0352 + 9d1f584 commit 53ab946
Show file tree
Hide file tree
Showing 46 changed files with 253 additions and 59 deletions.
94 changes: 84 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/arjunrajshekhar/terraform-provider-instaclustr
version: 2.1
commands:
build-provider:
steps:
- run:
name: "Build provider to binary"
command: make build
run-unit-tests:
steps:
- run:
name: "Run unit tests"
command: make test
run-acceptance-tests:
steps:
- run:
name: "Run acceptance tests"
command: |
export IC_USERNAME=${IC_TEST_USERNAME}
export IC_API_KEY=${IC_TEST_API_KEY}
export KMS_ARN=${IC_TEST_KMS_ARN}
export IC_PROV_ACC_NAME=${IC_TEST_PROV_ACC_NAME}
export IC_PROV_VPC_ID=${IC_TEST_PROV_VPC_ID}
make testacc
configure-gpg-key:
steps:
- checkout
- run: go get -v -t -d ./...
- run:
name: "Import GPG key"
command: |
Expand All @@ -24,6 +40,8 @@ jobs:
for keygrip in $(gpg --batch --yes --with-colons --with-keygrip --list-secret-keys ${GIT_EMAIL} | grep grp | sed 's|[grp:,]||g'); do
/usr/lib/gnupg2/gpg-preset-passphrase --preset --passphrase ${GPG_PASSPHRASE} ${keygrip}
done
package-all-platforms:
steps:
- run:
name: "Build for Windows, Linux and OSX and sign the assets"
command: |
Expand All @@ -44,16 +62,25 @@ jobs:
env GOOS=windows GOARCH=386 make build VERSION=${CIRCLE_TAG}
zip -j bin/${FULL_BIN_NAME}_windows_386.zip bin/${FULL_BIN_NAME}
rm bin/${FULL_BIN_NAME}
sign-builds:
steps:
- run:
name: "Sign builds with GPG and SHA256"
command: |
cd bin
shasum -a 256 *.zip > ${SHASUM_NAME}_SHA256SUMS
gpg --batch --detach-sign --yes ${SHASUM_NAME}_SHA256SUMS
clean-gpg-keys:
steps:
- run:
name: "Clean up GPG keys and kill agent"
command: |
for fingerprint in $(gpg --batch --yes --with-colons --fingerprint --list-secret-keys ${GIT_EMAIL} | grep fpr | sed 's|[fpr:,]||g'); do
gpg --batch --delete-secret-keys --yes ${fingerprint} || true
done
gpg-connect-agent "KILLAGENT" /bye
create-github-release:
steps:
- run:
name: "Publish Release on GitHub"
command: |
Expand All @@ -66,14 +93,61 @@ jobs:
-n "Release ${CIRCLE_TAG}" \
-b "Generated by Instaclustr's Circle CI account." \
${CIRCLE_TAG} ./bin/
jobs:
build:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/arjunrajshekhar/terraform-provider-instaclustr
steps:
- checkout
- run: go get -v -t -d ./...
- configure-gpg-key
- run-unit-tests
- build-provider
- package-all-platforms
- sign-builds
- clean-gpg-keys
- create-github-release
commit-build-test:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/arjunrajshekhar/terraform-provider-instaclustr
steps:
- checkout
- run: go get -v -t -d ./...
- build-provider
- run-unit-tests
pr-build-test:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/arjunrajshekhar/terraform-provider-instaclustr
steps:
- checkout
- run: go get -v -t -d ./...
- run-acceptance-tests
- build-provider
- package-all-platforms
workflows:
version: 2
build-and-deploy:
jobs:
- build:
context: terraform provider
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
commit-build-test-workflow:
jobs:
- commit-build-test
pr-build-test-workflow:
jobs:
- hold:
type: approval
filters:
branches:
ignore: master
- pr-build-test:
context: terraform provider
requires:
- hold
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

BIN_NAME="terraform-provider-instaclustr"

VERSION=v1.9.4
VERSION=v1.9.5

.PHONY: install clean all build test testacc testtarget release_version
release_version:
Expand All @@ -17,7 +17,7 @@ build:
go build $(FLAGS) -o bin/$(BIN_NAME)_$(VERSION) main.go

test:
cd test && go test -v -timeout 120m -count=1
go test -v -timeout 120m -count=1 ./...

testacc:
ifndef IC_USERNAME
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Terraform Instaclustr Provider

A [Terraform](http://terraform.io) provider for managing Instaclustr Platform resources.
[![CircleCI](https://img.shields.io/circleci/build/gh/instaclustr/terraform-provider-instaclustr/master?style=for-the-badge)](https://app.circleci.com/pipelines/github/instaclustr/terraform-provider-instaclustr)
![GoLang Version](https://img.shields.io/github/go-mod/go-version/instaclustr/terraform-provider-instaclustr?logo=go&style=for-the-badge)
![Latest Release Version](https://img.shields.io/github/v/release/instaclustr/terraform-provider-instaclustr?logo=github&sort=semver&style=for-the-badge)
![License](https://img.shields.io/github/license/instaclustr/terraform-provider-instaclustr?style=for-the-badge)

It provides a flexible set of resources for provisioning and managing [Instaclustr based clusters](http://instaclustr.com/) via the use of Terraform.
A [Terraform](http://terraform.io) provider for managing Instaclustr Platform resources.

It provides a flexible set of resources for provisioning and managing [Instaclustr based clusters](http://instaclustr.com/) via the use of Terraform.

For general information about Terraform, visit the [official website](https://terraform.io/) and [GitHub project page](https://github.com/hashicorp/terraform).

For further information about Instaclustr, please see [FAQ](https://www.instaclustr.com/resources/faqs/) and [Support](https://support.instaclustr.com/hc/en-us)
For further information about Instaclustr, please see [FAQ](https://www.instaclustr.com/resources/faqs/) and [Support](https://support.instaclustr.com/hc/en-us)

## Key benefits

Expand Down Expand Up @@ -114,7 +119,7 @@ A schema change has been made from 0.0.1 which no longer supports the `bundles`

## Contributing

Firstly thanks! We value your time and will do our best to review the PR as soon as possible.
Firstly thanks! We value your time and will do our best to review the PR as soon as possible.

1. [Install golang](https://golang.org/doc/install#install)
2. Clone repository to: $GOPATH/src/github.com/instaclustr/terraform-provider-instaclustr
Expand All @@ -124,6 +129,13 @@ Firstly thanks! We value your time and will do our best to review the PR as soo
6. Run the acceptance tests `$ make testacc`
7. Create a PR and send it our way :)

Our Circle CI pipeline will automatically run unit tests when a PR is created and new changes are committed.
It is also capable of running the acceptance tests, however our staff needs to give a manual approval to run the tests.
Passing tests are a requirement to merge a PR. Please let us know when your PR is ready for acceptance tests!

Unit tests are within `instaclustr` folder with `_unit_test` suffix, and used to test the internal methods.
Acceptance tests are within `acc_test` folder, and used to run end-to-end testing.

#### Acceptance Test Environment Variables
Variable | Command | Description
---------|-------------|--------
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 5 additions & 6 deletions test/api_client_test.go → instaclustr/api_client_unit_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package test
package instaclustr

import (
"fmt"
"io/ioutil"
"testing"
"github.com/instaclustr/terraform-provider-instaclustr/instaclustr"
)

func TestAPIClientRead(t *testing.T) {
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestAPIClientCreateNoNetwork(t *testing.T) {
t.Fatalf("Failed to load %s: %s", filename, err)
}

client := new(instaclustr.APIClient)
client := new(APIClient)
client.InitClient("http://127.0.0.1:5000", "Trisolaris", "DoNotAnswer!")
_, err = client.CreateCluster(jsonStr)
if err == nil {
Expand All @@ -94,7 +93,7 @@ func TestAPIClientCreateNoNetwork(t *testing.T) {

func TestAPIClientReadNoNetwork(t *testing.T) {
id := "77b5a4e1-c422-4a78-b551-d8fa5c42ad95"
client := new(instaclustr.APIClient)
client := new(APIClient)
client.InitClient("http://127.0.0.1:5000", "Trisolaris", "DoNotAnswer!")
_, err := client.ReadCluster(id)
if err == nil {
Expand All @@ -104,7 +103,7 @@ func TestAPIClientReadNoNetwork(t *testing.T) {

func TestAPIClientDeleteNoNetwork(t *testing.T) {
id := "77b5a4e1-c422-4a78-b551-d8fa5c42ad95"
client := new(instaclustr.APIClient)
client := new(APIClient)
client.InitClient("http://127.0.0.1:5000", "Trisolaris", "DoNotAnswer!")
err := client.DeleteCluster(id)
if err == nil {
Expand Down Expand Up @@ -179,4 +178,4 @@ func TestAPIClientCreateInvalidFirewall(t *testing.T) {
if err2 == nil {
t.Fatalf("Firewall creation expected error but got null: %s", err2)
}
}
}
16 changes: 5 additions & 11 deletions test/api_mock_client.go → instaclustr/api_mock_client.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package test
package instaclustr

import (
"net/http"
"time"

"github.com/instaclustr/terraform-provider-instaclustr/instaclustr"
)

type APIMockClient struct {
instaclustr.APIClient
}

// RoundTripFunc .
type RoundTripFunc func(request *http.Request) *http.Response

Expand All @@ -19,11 +13,11 @@ func (mockFunction RoundTripFunc) RoundTrip(request *http.Request) (*http.Respon
return mockFunction(request), nil
}

func (c *APIMockClient) InitClient(mockFunction RoundTripFunc) {
c.APIClient.InitClient("", "", "")
func (c *APIClient) InitMockClient(mockFunction RoundTripFunc) {
c.InitClient("", "", "")
var client = &http.Client{
Timeout: time.Second * 60,
Transport: RoundTripFunc(mockFunction),
}
c.APIClient.SetClient(client)
}
c.SetClient(client)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test
package instaclustr

import (
"bytes"
Expand All @@ -22,10 +22,10 @@ Where:
responseCode: is the api response code in this case 202
*/
func SetupMock(t *testing.T, request string, response string, responseCode int) *APIMockClient {
func SetupMock(t *testing.T, request string, response string, responseCode int) *APIClient {
requestString := fmt.Sprintf("/provisioning/v1/%s", request)
client := new(APIMockClient)
client.InitClient(func(req *http.Request) *http.Response {
client := new(APIClient)
client.InitMockClient(func(req *http.Request) *http.Response {
// Test request parameters
if req.URL.String() != requestString {
t.Fatalf("Unexpected request, expected '%s', but was '%s'", requestString, req.URL.String())
Expand Down
16 changes: 16 additions & 0 deletions instaclustr/provider_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package instaclustr

import (
"testing"
"github.com/hashicorp/terraform/terraform"
)

func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
15 changes: 12 additions & 3 deletions instaclustr/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -726,9 +727,16 @@ func getBundlesFromCluster(cluster *Cluster) ([]map[string]interface{}, error) {

bundles := make([]map[string]interface{}, 0)
bundles = append(bundles, baseBundle)
if cluster.AddonBundles != nil {
for _, addonBundle := range cluster.AddonBundles{
bundles = append(bundles, addonBundle)
addonBundles := cluster.AddonBundles

if addonBundles == nil {
return nil, nil
}

sort.Slice(addonBundles, func(i, j int) bool {return addonBundles[i]["bundle"].(string) > addonBundles[j]["bundle"].(string)})
for _, addonBundle := range addonBundles {
if len(addonBundle) != 0 {
bundles = append(bundles, addonBundle)
}
}

Expand Down Expand Up @@ -799,6 +807,7 @@ func getBundles(d *schema.ResourceData) ([]Bundle, error) {
}
bundles = append(bundles, bundle)
}

return bundles, nil
}

Expand Down
Loading

0 comments on commit 53ab946

Please sign in to comment.