Skip to content

Commit 9ba1d4e

Browse files
committed
transformation tests
1 parent da1a0e4 commit 9ba1d4e

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ go 1.23.4
44

55
require (
66
github.com/hashicorp/hcl/v2 v2.23.0
7+
github.com/sebdah/goldie/v2 v2.5.5
78
github.com/spf13/afero v1.12.0
89
github.com/spf13/cobra v1.8.1
10+
github.com/stretchr/testify v1.4.0
911
)
1012

1113
require (
1214
github.com/agext/levenshtein v1.2.1 // indirect
1315
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
16+
github.com/davecgh/go-spew v1.1.1 // indirect
1417
github.com/google/go-cmp v0.6.0 // indirect
1518
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1619
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
1720
github.com/pmezard/go-difflib v1.0.0 // indirect
18-
github.com/sebdah/goldie/v2 v2.5.5 // indirect
1921
github.com/sergi/go-diff v1.3.1 // indirect
2022
github.com/spf13/pflag v1.0.5 // indirect
2123
github.com/zclconf/go-cty v1.16.2 // indirect
2224
golang.org/x/mod v0.22.0 // indirect
2325
golang.org/x/sync v0.10.0 // indirect
2426
golang.org/x/text v0.21.0 // indirect
2527
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
28+
gopkg.in/yaml.v2 v2.4.0 // indirect
2629
)

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3q
1414
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
1515
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1616
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
17+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1718
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
1819
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
20+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1921
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2022
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
2123
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
@@ -36,6 +38,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
3638
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3739
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3840
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
41+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
3942
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
4043
github.com/zclconf/go-cty v1.16.2 h1:LAJSwc3v81IRBZyUVQDUdZ7hs3SYs9jv0eZJDWHD/70=
4144
github.com/zclconf/go-cty v1.16.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
@@ -50,7 +53,9 @@ golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
5053
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
5154
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
5255
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
56+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
5357
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5458
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
59+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
5560
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
5661
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/hcl/hcl_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package hcl_test
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
"testing"
7+
8+
"github.com/mongodb-labs/atlas-cli-plugin-terraform/internal/hcl"
9+
"github.com/sebdah/goldie/v2"
10+
"github.com/spf13/afero"
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestClusterToAdvancedCluster(t *testing.T) {
16+
const (
17+
root = "testdata/clu2adv"
18+
inSuffix = ".in.tf"
19+
outSuffix = ".out.tf"
20+
)
21+
g := goldie.New(t,
22+
goldie.WithFixtureDir(root),
23+
goldie.WithNameSuffix(outSuffix))
24+
fs := afero.NewOsFs()
25+
pattern := filepath.Join(root, "*"+inSuffix)
26+
inputFiles, err := afero.Glob(fs, pattern)
27+
require.NoError(t, err)
28+
assert.NotEmpty(t, inputFiles)
29+
for _, inputFile := range inputFiles {
30+
testName := strings.TrimSuffix(filepath.Base(inputFile), inSuffix)
31+
inConfig, err := afero.ReadFile(fs, inputFile)
32+
require.NoError(t, err)
33+
outConfig, err := hcl.ClusterToAdvancedCluster(inConfig)
34+
require.NoError(t, err)
35+
g.Assert(t, testName, outConfig)
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "resource1" "res1" {
2+
name = "name1"
3+
}
4+
5+
resource "mongodbatlas_cluster" "cluster1" {
6+
name = "name2"
7+
}
8+
9+
data "resource2" "res2" {
10+
name = "name3"
11+
}
12+
13+
data "mongodbatlas_cluster" "cluster2" {
14+
name = "name4"
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "resource1" "res1" {
2+
name = "name1"
3+
}
4+
5+
resource "mongodbatlas_advanced_cluster" "cluster1" {
6+
name = "name2"
7+
}
8+
9+
data "resource2" "res2" {
10+
name = "name3"
11+
}
12+
13+
data "mongodbatlas_cluster" "cluster2" {
14+
name = "name4"
15+
}

0 commit comments

Comments
 (0)