Skip to content

Commit

Permalink
Merge pull request incentro-ecx#21 from incentro-dc/feat/integration-…
Browse files Browse the repository at this point in the history
…tests

Feat/integration tests
  • Loading branch information
Thomas De Meyer authored Sep 28, 2022
2 parents 442dcd9 + 32e6cf3 commit 8f12644
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
COMMERCELAYER_CLIENT_ID=<commercelayer-client-id>
COMMERCELAYER_CLIENT_SECRET=<commercelayer-client-secret>
COMMERCELAYER_API_ENDPOINT=<commercelayer-api-endpoint>
COMMERCELAYER_AUTH_ENDPOINT=<commercelayer-auth-endpoint>
32 changes: 30 additions & 2 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run tests
name: run tests

on:
pull_request:
Expand Down Expand Up @@ -26,4 +26,32 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '1.18'
- run: go test -v -cover ./...
- run: go test -v -cover ./...

acceptance-tests:
name: Acceptance Tests (Terraform ${{ matrix.terraform-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform-version:
# - '1.0.*'
# - '1.1.*'
- '1.2.*'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18'
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ matrix.terraform-version }}
terraform_wrapper: false
- run: go test -v -p 1 ./...
env:
# TODO: switch to mocked server at some point, as this runs live
TF_ACC: '1'
COMMERCELAYER_CLIENT_ID: ${{ secrets.COMMERCELAYER_CLIENT_ID }}
COMMERCELAYER_CLIENT_SECRET: ${{ secrets.COMMERCELAYER_CLIENT_SECRET }}
COMMERCELAYER_API_ENDPOINT: ${{ secrets.COMMERCELAYER_API_ENDPOINT }}
COMMERCELAYER_AUTH_ENDPOINT: ${{ secrets.COMMERCELAYER_AUTH_ENDPOINT }}
84 changes: 81 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,84 @@
/.DS_Store
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Project
/terraform-provider-commercelayer
/examples/**/*.tfstate*
/examples/**/*.tfvars
/bin
/dist/
/examples/**/*.lock.hcl
/examples/**/.terraform
/bin/
/dist/
/.env
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/runConfigurations/run_acceptance_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/run_provider.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/runConfigurations/run_unit_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/terraform-provider-commercelayer.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions commercelayer/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package commercelayer

import (
"bytes"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
"os"
"testing"
"text/template"
)

func init() {
testAccProviderCommercelayer = Provider()
testAccProviderFactories = map[string]func() (*schema.Provider, error){
"commercelayer": func() (*schema.Provider, error) {
return testAccProviderCommercelayer, nil
},
}
}

var testAccProviderCommercelayer *schema.Provider
var testAccProviderFactories = map[string]func() (*schema.Provider, error){}

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

func testAccPreCheck(t *testing.T) {
requiredEnvs := []string{
"COMMERCELAYER_CLIENT_ID",
"COMMERCELAYER_CLIENT_SECRET",
"COMMERCELAYER_API_ENDPOINT",
"COMMERCELAYER_AUTH_ENDPOINT",
}
for _, val := range requiredEnvs {
if os.Getenv(val) == "" {
t.Fatalf("%v must be set for acceptance tests", val)
}
}
}

func hclTemplate(data string, params map[string]any) string {
var out bytes.Buffer
tmpl := template.Must(template.New("hcl").Parse(data))
err := tmpl.Execute(&out, params)
if err != nil {
log.Fatal(err)
}
return out.String()
}
Loading

0 comments on commit 8f12644

Please sign in to comment.