chore: update actions goreleaser

This commit is contained in:
Marcel_Henselin 2026-02-24 13:58:16 +01:00
parent 4a2819787d
commit cc08fca97a
10 changed files with 215 additions and 792 deletions

View file

@ -22,6 +22,8 @@ runs:
apt-get -y -qq update apt-get -y -qq update
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget
- name: Checkout
uses: actions/checkout@v6
- name: Install Go ${{ inputs.go-version }} - name: Install Go ${{ inputs.go-version }}
uses: actions/setup-go@v6 uses: actions/setup-go@v6
@ -35,10 +37,9 @@ runs:
run: | run: |
set -e set -e
go install golang.org/x/tools/cmd/goimports@latest go install golang.org/x/tools/cmd/goimports@latest
go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest # go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest # go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.24.0 # go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.24.0
- name: Setup JAVA ${{ inputs.java-distribution }} ${{ inputs.go-version }} - name: Setup JAVA ${{ inputs.java-distribution }} ${{ inputs.go-version }}
uses: actions/setup-java@v5 uses: actions/setup-java@v5
@ -46,16 +47,12 @@ runs:
distribution: ${{ inputs.java-distribution }} # See 'Supported distributions' for available options distribution: ${{ inputs.java-distribution }} # See 'Supported distributions' for available options
java-version: ${{ inputs.java-version }} java-version: ${{ inputs.java-version }}
- name: Checkout
uses: actions/checkout@v6
- name: Run build pkg directory - name: Run build pkg directory
shell: bash shell: bash
run: | run: |
set -e set -e
go run cmd/main.go build go run cmd/main.go build
- name: Run make to build app - name: Run make to build app
shell: bash shell: bash
run: | run: |

View file

@ -83,7 +83,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }} GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: release --skip publish --clean --snapshot args: release --skip publish --clean --snapshot
@ -171,6 +171,16 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
- uses: actions/cache@v5
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: /install.sh
- name: Build - name: Build
uses: ./.github/actions/build uses: ./.github/actions/build
with: with:
@ -193,37 +203,13 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v9 uses: golangci/golangci-lint-action@v9
with: with:
version: v2.9 version: v2.10
args: --config=golang-ci.yaml --allow-parallel-runners --timeout=5m args: --config=golang-ci.yaml --allow-parallel-runners --timeout=5m
continue-on-error: true continue-on-error: true
- name: Linting - name: Linting terraform files
run: make lint run: make lint-tf
continue-on-error: true continue-on-error: true
# - name: Testing
# run: make test
#
# - name: Acceptance Testing
# if: ${{ github.event_name == 'pull_request' }}
# run: make test-acceptance-tf
#
# - name: Check coverage threshold
# shell: bash
# run: |
# make coverage
# COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
# echo "Coverage: $COVERAGE%"
# if (( $(echo "$COVERAGE < 80" | bc -l) )); then
# echo "Coverage is below 80%"
# # exit 1
# fi
# - name: Archive code coverage results
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
# path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
config: config:
if: ${{ github.event_name != 'schedule' }} if: ${{ github.event_name != 'schedule' }}
@ -234,7 +220,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
- name: Check GoReleaser - name: Check GoReleaser
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: check args: check

View file

@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
- name: Check GoReleaser - name: Check GoReleaser
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: check args: check
@ -93,7 +93,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }} GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: release --skip publish --clean --snapshot args: release --skip publish --clean --snapshot
@ -103,7 +103,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }} GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: release --skip publish --clean args: release --skip publish --clean

View file

@ -32,7 +32,7 @@ jobs:
with: with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
args: release --clean args: release --clean
env: env:

View file

@ -17,7 +17,8 @@ lint-golangci-lint:
lint-tf: lint-tf:
@echo "Linting terraform files" @echo "Linting terraform files"
@terraform fmt -check -diff -recursive @terraform fmt -check -diff -recursive examples/
@terraform fmt -check -diff -recursive stackit/
lint: lint-golangci-lint lint-tf lint: lint-golangci-lint lint-tf

View file

@ -169,7 +169,7 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueMust( m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueMust(
postgresflexalphadatasource.ConnectionInfoValue{}.AttributeTypes(ctx), postgresflexalphadatasource.ConnectionInfoValue{}.AttributeTypes(ctx),
map[string]attr.Value{ map[string]attr.Value{
"write": postgresflexalphadatasource.NewWriteValueMust( "write": types.ObjectValueMust(
postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx), postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx),
map[string]attr.Value{ map[string]attr.Value{
"host": types.StringPointerValue(resp.ConnectionInfo.Write.Host), "host": types.StringPointerValue(resp.ConnectionInfo.Write.Host),

View file

@ -1,746 +1,186 @@
package postgresflexalpha package postgresflexalpha
import ( import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/core/utils"
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha" postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
utils2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
) )
//nolint:unused // TODO: remove when used func Test_handleConnectionInfo(t *testing.T) {
type testFlavor struct { type args struct {
Cpu int64 ctx context.Context
Description string m *dataSourceModel
Id string hostName string
MaxGB int64 port int64
Memory int64
MinGB int64
NodeType string
StorageClasses []testFlavorStorageClass
}
//nolint:unused // TODO: remove when used
type testFlavorStorageClass struct {
Class string
MaxIoPerSec int64
MaxThroughInMb int64
}
//nolint:unused // TODO: remove when used
var responseList = []testFlavor{
{
Cpu: 1,
Description: "flavor 1.1",
Id: "flv1.1",
MaxGB: 500,
Memory: 1,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.2",
Id: "flv1.2",
MaxGB: 500,
Memory: 2,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.3",
Id: "flv1.3",
MaxGB: 500,
Memory: 3,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.4",
Id: "flv1.4",
MaxGB: 500,
Memory: 4,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.5",
Id: "flv1.5",
MaxGB: 500,
Memory: 5,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.6",
Id: "flv1.6",
MaxGB: 500,
Memory: 6,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.7",
Id: "flv1.7",
MaxGB: 500,
Memory: 7,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.8",
Id: "flv1.8",
MaxGB: 500,
Memory: 8,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.9",
Id: "flv1.9",
MaxGB: 500,
Memory: 9,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
/* ......................................................... */
{
Cpu: 2,
Description: "flavor 2.1",
Id: "flv2.1",
MaxGB: 500,
Memory: 1,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.2",
Id: "flv2.2",
MaxGB: 500,
Memory: 2,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.3",
Id: "flv2.3",
MaxGB: 500,
Memory: 3,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.4",
Id: "flv2.4",
MaxGB: 500,
Memory: 4,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.5",
Id: "flv2.5",
MaxGB: 500,
Memory: 5,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.6",
Id: "flv2.6",
MaxGB: 500,
Memory: 6,
MinGB: 5,
NodeType: "single",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
/* ......................................................... */
{
Cpu: 1,
Description: "flavor 1.1 replica",
Id: "flv1.1r",
MaxGB: 500,
Memory: 1,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.2 replica",
Id: "flv1.2r",
MaxGB: 500,
Memory: 2,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.3 replica",
Id: "flv1.3r",
MaxGB: 500,
Memory: 3,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.4 replica",
Id: "flv1.4r",
MaxGB: 500,
Memory: 4,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.5 replica",
Id: "flv1.5r",
MaxGB: 500,
Memory: 5,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 1,
Description: "flavor 1.6 replica",
Id: "flv1.6r",
MaxGB: 500,
Memory: 6,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
/* ......................................................... */
{
Cpu: 2,
Description: "flavor 2.1 replica",
Id: "flv2.1r",
MaxGB: 500,
Memory: 1,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.2 replica",
Id: "flv2.2r",
MaxGB: 500,
Memory: 2,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.3 replica",
Id: "flv2.3r",
MaxGB: 500,
Memory: 3,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.4 replica",
Id: "flv2.4r",
MaxGB: 500,
Memory: 4,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.5 replica",
Id: "flv2.5r",
MaxGB: 500,
Memory: 5,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
{
Cpu: 2,
Description: "flavor 2.6 replica",
Id: "flv2.6r",
MaxGB: 500,
Memory: 6,
MinGB: 5,
NodeType: "Replica",
StorageClasses: []testFlavorStorageClass{
{Class: "sc1", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc2", MaxIoPerSec: 0, MaxThroughInMb: 0},
{Class: "sc3", MaxIoPerSec: 0, MaxThroughInMb: 0},
},
},
/* ......................................................... */
}
//nolint:unused // TODO: remove when used
func testFlavorListToResponseFlavorList(f []testFlavor) []postgresflex.ListFlavors {
result := make([]postgresflex.ListFlavors, len(f))
for i, flavor := range f {
result[i] = testFlavorToResponseFlavor(flavor)
} }
return result tests := []struct {
} name string
args args
//nolint:unused // TODO: remove when used }{
func testFlavorToResponseFlavor(f testFlavor) postgresflex.ListFlavors { {
var scList []postgresflex.FlavorStorageClassesStorageClass name: "empty connection info",
for _, fl := range f.StorageClasses { args: args{
scList = append( ctx: context.TODO(),
scList, postgresflex.FlavorStorageClassesStorageClass{ m: &dataSourceModel{},
Class: utils.Ptr(fl.Class), hostName: "",
MaxIoPerSec: utils.Ptr(fl.MaxIoPerSec), port: 0,
MaxThroughInMb: utils.Ptr(fl.MaxThroughInMb),
}, },
) },
{
name: "empty connection info host",
args: args{
ctx: context.TODO(),
m: &dataSourceModel{},
hostName: "",
port: 1234,
},
},
{
name: "empty connection info port",
args: args{
ctx: context.TODO(),
m: &dataSourceModel{},
hostName: "hostname",
port: 0,
},
},
{
name: "valid connection info",
args: args{
ctx: context.TODO(),
m: &dataSourceModel{},
hostName: "host",
port: 1000,
},
},
} }
return postgresflex.ListFlavors{ for _, tt := range tests {
Cpu: utils.Ptr(f.Cpu), t.Run(tt.name, func(t *testing.T) {
Description: utils.Ptr(f.Description), resp := &postgresflex.GetInstanceResponse{
Id: utils.Ptr(f.Id), ConnectionInfo: &postgresflex.InstanceConnectionInfo{
MaxGB: utils.Ptr(f.MaxGB), Write: &postgresflex.InstanceConnectionInfoWrite{
Memory: utils.Ptr(f.Memory), Host: utils.Ptr(tt.args.hostName),
MinGB: utils.Ptr(f.MinGB), Port: utils.Ptr(tt.args.port),
NodeType: utils.Ptr(f.NodeType), },
StorageClasses: &scList, },
}
handleConnectionInfo(tt.args.ctx, tt.args.m, resp)
if tt.args.hostName == "" || tt.args.port == 0 {
if !tt.args.m.ConnectionInfo.IsNull() {
t.Errorf("expected connection info to be null")
}
}
if tt.args.hostName != "" && tt.args.port != 0 {
res := tt.args.m.ConnectionInfo.Write.Attributes()
gotHost := ""
if r, ok := res["host"]; ok {
gotHost = utils2.RemoveQuotes(r.String())
}
if gotHost != tt.args.hostName {
t.Errorf("host value incorrect: want: %s - got: %s", tt.args.hostName, gotHost)
}
gotPort, ok := res["port"]
if !ok {
t.Errorf("could not find a value for port in connection_info.write")
}
if !gotPort.Equal(types.Int64Value(tt.args.port)) {
t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String())
}
}
})
} }
} }
// func Test_getAllFlavors(t *testing.T) { func Test_handleEncryption(t *testing.T) {
// type args struct { type args struct {
// projectId string m *dataSourceModel
// region string resp *postgresflex.GetInstanceResponse
// } }
// tests := []struct { tests := []struct {
// name string name string
// args args args args
// firstItem int }{
// lastItem int // TODO: Add test cases.
// want []postgresflex.ListFlavors }
// wantErr bool for _, tt := range tests {
// }{ t.Run(tt.name, func(t *testing.T) {
// { handleEncryption(tt.args.m, tt.args.resp)
// name: "find exactly one flavor", })
// args: args{ }
// projectId: "project", }
// region: "region",
// },
// firstItem: 0,
// lastItem: 0,
// want: []postgresflex.ListFlavors{
// testFlavorToResponseFlavor(responseList[0]),
// },
// wantErr: false,
// },
// {
// name: "get exactly 1 page flavors",
// args: args{
// projectId: "project",
// region: "region",
// },
// firstItem: 0,
// lastItem: 9,
// want: testFlavorListToResponseFlavorList(responseList[0:10]),
// wantErr: false,
// },
// {
// name: "get exactly 20 flavors",
// args: args{
// projectId: "project",
// region: "region",
// },
// firstItem: 0,
// lastItem: 20,
// // 0 indexed therefore we want :21
// want: testFlavorListToResponseFlavorList(responseList[0:21]),
// wantErr: false,
// },
// {
// name: "get all flavors",
// args: args{
// projectId: "project",
// region: "region",
// },
// firstItem: 0,
// lastItem: len(responseList),
// want: testFlavorListToResponseFlavorList(responseList),
// wantErr: false,
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// first := tt.firstItem
// if first > len(responseList)-1 {
// first = len(responseList) - 1
// }
// last := tt.lastItem
// if last > len(responseList)-1 {
// last = len(responseList) - 1
// }
// mockClient := postgresFlexClientMocked{
// returnError: tt.wantErr,
// firstItem: first,
// lastItem: last,
// }
// got, err := getAllFlavors(context.TODO(), mockClient, tt.args.projectId, tt.args.region)
// if (err != nil) != tt.wantErr {
// t.Errorf("getAllFlavors() error = %v, wantErr %v", err, tt.wantErr)
// return
// }
//
// if diff := cmp.Diff(tt.want, got); diff != "" {
// t.Errorf("mismatch (-want +got):\n%s", diff)
// }
//
// if !reflect.DeepEqual(got, tt.want) {
// t.Errorf("getAllFlavors() got = %v, want %v", got, tt.want)
// }
// })
// }
//}
// func Test_loadFlavorId(t *testing.T) { func Test_handleNetwork(t *testing.T) {
// type args struct { type args struct {
// ctx context.Context ctx context.Context
// model *Model m *dataSourceModel
// storage *storageModel resp *postgresflex.GetInstanceResponse
// } }
// tests := []struct { tests := []struct {
// name string name string
// args args args args
// firstItem int wantErr bool
// lastItem int }{
// want []postgresflex.ListFlavors // TODO: Add test cases.
// wantErr bool }
// }{ for _, tt := range tests {
// { t.Run(tt.name, func(t *testing.T) {
// name: "find a single flavor", if err := handleNetwork(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
// args: args{ t.Errorf("handleNetwork() error = %v, wantErr %v", err, tt.wantErr)
// ctx: context.Background(), }
// model: &Model{ })
// ProjectId: basetypes.NewStringValue("project"), }
// Region: basetypes.NewStringValue("region"), }
// },
// storage: &storageModel{ func Test_mapGetDataInstanceResponseToModel(t *testing.T) {
// Class: basetypes.NewStringValue("sc1"), type args struct {
// Size: basetypes.NewInt64Value(100), ctx context.Context
// }, m *dataSourceModel
// }, resp *postgresflex.GetInstanceResponse
// firstItem: 0, }
// lastItem: 3, tests := []struct {
// want: []postgresflex.ListFlavors{ name string
// testFlavorToResponseFlavor(responseList[0]), args args
// }, wantErr bool
// wantErr: false, }{
// }, // TODO: Add test cases.
// { }
// name: "find a single flavor by replicas option", for _, tt := range tests {
// args: args{ t.Run(tt.name, func(t *testing.T) {
// ctx: context.Background(), if err := mapGetDataInstanceResponseToModel(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
// model: &Model{ t.Errorf("mapGetDataInstanceResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
// ProjectId: basetypes.NewStringValue("project"), }
// Region: basetypes.NewStringValue("region"), })
// Replicas: basetypes.NewInt64Value(1), }
// }, }
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"), func Test_mapGetInstanceResponseToModel(t *testing.T) {
// Size: basetypes.NewInt64Value(100), type args struct {
// }, ctx context.Context
// }, m *postgresflexalpharesource.InstanceModel
// firstItem: 0, resp *postgresflex.GetInstanceResponse
// lastItem: 3, }
// want: []postgresflex.ListFlavors{ tests := []struct {
// testFlavorToResponseFlavor(responseList[0]), name string
// }, args args
// wantErr: false, wantErr bool
// }, }{
// { // TODO: Add test cases.
// name: "fail finding find a single flavor by replicas option", }
// args: args{ for _, tt := range tests {
// ctx: context.Background(), t.Run(tt.name, func(t *testing.T) {
// model: &Model{ if err := mapGetInstanceResponseToModel(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
// ProjectId: basetypes.NewStringValue("project"), t.Errorf("mapGetInstanceResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
// Region: basetypes.NewStringValue("region"), }
// Replicas: basetypes.NewInt64Value(1), })
// }, }
// storage: &storageModel{ }
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 13,
// lastItem: 23,
// want: []postgresflex.ListFlavors{},
// wantErr: true,
// },
// {
// name: "find a replicas flavor lower case",
// args: args{
// ctx: context.Background(),
// model: &Model{
// ProjectId: basetypes.NewStringValue("project"),
// Region: basetypes.NewStringValue("region"),
// },
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 0,
// lastItem: len(responseList) - 1,
// want: []postgresflex.ListFlavors{
// testFlavorToResponseFlavor(responseList[16]),
// },
// wantErr: false,
// },
// {
// name: "find a replicas flavor CamelCase",
// args: args{
// ctx: context.Background(),
// model: &Model{
// ProjectId: basetypes.NewStringValue("project"),
// Region: basetypes.NewStringValue("region"),
// },
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 0,
// lastItem: len(responseList) - 1,
// want: []postgresflex.ListFlavors{
// testFlavorToResponseFlavor(responseList[16]),
// },
// wantErr: false,
// },
// {
// name: "find a replicas flavor by replicas option",
// args: args{
// ctx: context.Background(),
// model: &Model{
// ProjectId: basetypes.NewStringValue("project"),
// Region: basetypes.NewStringValue("region"),
// Replicas: basetypes.NewInt64Value(3),
// },
// flavor: &flavorModel{
// CPU: basetypes.NewInt64Value(1),
// RAM: basetypes.NewInt64Value(1),
// },
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 0,
// lastItem: len(responseList) - 1,
// want: []postgresflex.ListFlavors{
// testFlavorToResponseFlavor(responseList[16]),
// },
// wantErr: false,
// },
// {
// name: "fail finding a replica flavor",
// args: args{
// ctx: context.Background(),
// model: &Model{
// ProjectId: basetypes.NewStringValue("project"),
// Region: basetypes.NewStringValue("region"),
// Replicas: basetypes.NewInt64Value(3),
// },
// flavor: &flavorModel{
// CPU: basetypes.NewInt64Value(1),
// RAM: basetypes.NewInt64Value(1),
// },
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 0,
// lastItem: 10,
// want: []postgresflex.ListFlavors{},
// wantErr: true,
// },
// {
// name: "no flavor found error",
// args: args{
// ctx: context.Background(),
// model: &Model{
// ProjectId: basetypes.NewStringValue("project"),
// Region: basetypes.NewStringValue("region"),
// },
// flavor: &flavorModel{
// CPU: basetypes.NewInt64Value(10),
// RAM: basetypes.NewInt64Value(1000),
// NodeType: basetypes.NewStringValue("Single"),
// },
// storage: &storageModel{
// Class: basetypes.NewStringValue("sc1"),
// Size: basetypes.NewInt64Value(100),
// },
// },
// firstItem: 0,
// lastItem: 3,
// want: []postgresflex.ListFlavors{},
// wantErr: true,
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// first := tt.firstItem
// if first > len(responseList)-1 {
// first = len(responseList) - 1
// }
// last := tt.lastItem
// if last > len(responseList)-1 {
// last = len(responseList) - 1
// }
// mockClient := postgresFlexClientMocked{
// returnError: tt.wantErr,
// firstItem: first,
// lastItem: last,
// }
// if err := loadFlavorId(tt.args.ctx, mockClient, tt.args.model, tt.args.flavor, tt.args.storage); (err != nil) != tt.wantErr {
// t.Errorf("loadFlavorId() error = %v, wantErr %v", err, tt.wantErr)
// }
// })
// }
//}

View file

@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/core/config"
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha" postgresflexalphaPkgGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance" postgresflexalphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils" "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
// The fwresource import alias is so there is no collision // The fwresource import alias is so there is no collision
@ -36,7 +36,7 @@ func init() {
F: func(_ string) error { // region is passed by the testing framework F: func(_ string) error { // region is passed by the testing framework
ctx := context.Background() ctx := context.Background()
apiClientConfigOptions := []config.ConfigurationOption{} apiClientConfigOptions := []config.ConfigurationOption{}
apiClient, err := postgresflexalpha2.NewAPIClient(apiClientConfigOptions...) apiClient, err := postgresflexalphaPkgGen.NewAPIClient(apiClientConfigOptions...)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@ -80,7 +80,7 @@ func TestInstanceResourceSchema(t *testing.T) {
schemaResponse := &fwresource.SchemaResponse{} schemaResponse := &fwresource.SchemaResponse{}
// Instantiate the resource.Resource and call its Schema method // Instantiate the resource.Resource and call its Schema method
postgresflexalpha.NewInstanceResource().Schema(ctx, schemaRequest, schemaResponse) postgresflexalphaInstance.NewInstanceResource().Schema(ctx, schemaRequest, schemaResponse)
if schemaResponse.Diagnostics.HasError() { if schemaResponse.Diagnostics.HasError() {
t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics) t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics)
@ -402,19 +402,6 @@ func TestAccInstanceWithDatabases(t *testing.T) {
// // Run unit tests against mock // // Run unit tests against mock
//} //}
// type postgresFlexClientMocked struct {
// returnError bool
// getFlavorsResp *postgresflex.GetFlavorsResponse
// }
//
// func (c *postgresFlexClientMocked) ListFlavorsExecute(_ context.Context, _, _ string) (*postgresflex.GetFlavorsResponse, error) {
// if c.returnError {
// return nil, fmt.Errorf("get flavors failed")
// }
//
// return c.getFlavorsResp, nil
// }
// func TestNewInstanceResource(t *testing.T) { // func TestNewInstanceResource(t *testing.T) {
// exData := resData{ // exData := resData{
// Region: "eu01", // Region: "eu01",

View file

@ -12,7 +12,7 @@ resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only"
size = 10 size = 10
} }
network = { network = {
acl = ["0.0.0.0/0"] acl = ["0.0.0.0/0"]
access_scope = "PUBLIC" access_scope = "PUBLIC"
} }
version = 17 version = 17

View file

@ -0,0 +1,12 @@
package utils
func RemoveQuotes(src string) string {
var res string
if len(src) > 0 && src[0] == '"' {
res = src[1:]
}
if len(res) > 0 && res[len(res)-1] == '"' {
res = res[:len(res)-1]
}
return res
}