Skip to content

Commit

Permalink
chore: added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Nov 9, 2023
1 parent 87ccfe0 commit 61be6fd
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,74 @@ jobs:
- run: go test -v -cover ./...
env:
TF_ACC: '1'
integration:
name: Integration (Terraform ${{ matrix.terraform-version }})
runs-on: ubuntu-latest
services:
mysql8prod:
image: mysql:8
env:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: pass
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10
mysql8dev:
image: mysql:8
env:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: pass
ports:
- 3307:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10
strategy:
fail-fast: false
matrix:
terraform-version:
- '1.2.*'
- '1.3.*'
- '1.4.*'
- '1.5.*'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21'
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ matrix.terraform-version }}
terraform_wrapper: false
- name: Run GoReleaser
id: goreleaser
uses: goreleaser/[email protected]
with:
version: latest
args: release --skip=validate,publish,sign --clean
env:
GORELEASER_CURRENT_TAG: v0.0.0-pre.0
- name: Create local plugin
run: |
./scripts/local.sh ./examples/testcase 0.0.0-pre.0
- name: Terraform
working-directory: examples/testcase
run: |
terraform init
terraform apply --auto-approve
env:
TF_LOG: DEBUG
3 changes: 3 additions & 0 deletions examples/testcase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform.lock.hcl
.terraform/*
terraform.d
19 changes: 19 additions & 0 deletions examples/testcase/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
atlas = {
source = "ariga/atlas"
version = "0.0.0-pre.0"
}
}
}

data "atlas_schema" "db" {
src = "file://schema.sql"
dev_url = "sqlite://file?mode=memory"
}

resource "atlas_schema" "db" {
hcl = data.atlas_schema.db.hcl
url = "sqlite://file.db"
dev_url = "sqlite://file?mode=memory"
}
5 changes: 5 additions & 0 deletions examples/testcase/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE t1 (
c1 INT,
c2 TEXT,
PRIMARY KEY (c1)
);
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func (p *AtlasProvider) Configure(ctx context.Context, req provider.ConfigureReq
resp.Diagnostics.AddError("Unable to find atlas-cli", err.Error())
return
}
tflog.Debug(ctx, "Found atlas-cli", map[string]any{
"path": atlasPath,
})
c, err := atlas.NewClient("", atlasPath)
if err != nil {
resp.Diagnostics.AddError("Failed to create client", err.Error())
Expand Down
13 changes: 13 additions & 0 deletions scripts/local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

HOSTNAME=registry.terraform.io
NAMESPACE=ariga
TYPE=atlas
VERSION=${2:-0.0.0-pre.0}
TARGET=$(go env GOOS)_$(go env GOARCH)
PACKED="terraform-provider-${TYPE}_${VERSION}_${TARGET}.zip"

PLUGIN_ADDR="${HOSTNAME}/${NAMESPACE}/${TYPE}"
PLUGIN_PATH="${1}/terraform.d/plugins/${PLUGIN_ADDR}"
mkdir -p $PLUGIN_PATH
cp ./dist/${PACKED} $PLUGIN_PATH

0 comments on commit 61be6fd

Please sign in to comment.