Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added integration tests #101

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2.9.1
uses: goreleaser/goreleaser-action@v5.0.0
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GitHub sets this automatically
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,65 @@ jobs:
- run: go test -v -cover ./...
env:
TF_ACC: '1'
build-dev:
name: Build provider bundles
runs-on: ubuntu-latest
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-
- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
version: latest
args: release --clean --skip=validate,publish,sign
env:
GORELEASER_CURRENT_TAG: v0.0.0-pre.0
- uses: actions/upload-artifact@v3
with:
name: atlas-provider
path: ./dist/terraform-provider-atlas_0.0.0-pre.0_linux_amd64.zip
retention-days: 5
if-no-files-found: error
integration:
name: Integration (Terraform ${{ matrix.terraform-version }})
runs-on: ubuntu-latest
needs: [build-dev]
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/download-artifact@v3
with:
name: atlas-provider
path: ./dist
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ matrix.terraform-version }}
terraform_wrapper: false
- 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