Skip to content

Commit ae28cfe

Browse files
committed
Mix testS
1 parent 029b2df commit ae28cfe

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

0

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
: 1705060750:0;curl --http-proxy 103.48.69.113:83 ip.me
2+
: 1705060770:0;curl -x 103.48.69.113:83 ip.me
3+
: 1705060780:0;curl -x 223.247.46.182:8089\
4+
ip.me
5+
: 1705060783:0;curl -x 223.247.46.182:8089 ip .me\
6+
ip.me
7+
: 1705060786:0;curl -x 223.247.46.182:8089 ip.me\
8+
ip.me
9+
: 1705060791:0;curl -x 223.247.46.182:8089 tojek.pl\
10+
ip.me
11+
: 1705060799:0;curl -x 134.122.5.111:48978 tojek.pl
12+
: 1705060807:0;curl -x 193.56.255.181:3128 tojek.pl
13+
: 1705060813:0;curl -x 210.200.169.134:33333 tojek.pl
14+
: 1705062310:0;gss
15+
: 1705062312:0;git add --all

cli/templatevariables.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,8 @@ func combineVariableValues(valuesSets ...[]codersdk.VariableValue) []codersdk.Va
267267
result = append(result, codersdk.VariableValue{Name: name, Value: value})
268268
}
269269

270+
sort.Slice(result, func(i, j int) bool {
271+
return result[i].Name < result[j].Name
272+
})
270273
return result
271274
}

cli/templatevariables_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
"github.com/coder/coder/v2/cli"
11+
"github.com/coder/coder/v2/codersdk"
1112
)
1213

1314
func TestDiscoverVarsFiles(t *testing.T) {
@@ -60,3 +61,56 @@ func TestDiscoverVarsFiles(t *testing.T) {
6061
}
6162
require.EqualValues(t, expected, found)
6263
}
64+
65+
func TestParseVariableValuesFromVarsFiles(t *testing.T) {
66+
t.Parallel()
67+
68+
// Given
69+
const (
70+
hclFilename1 = "file1.tfvars"
71+
hclFilename2 = "file2.tfvars"
72+
jsonFilename3 = "file3.tfvars.json"
73+
jsonFilename4 = "file4.tfvars.json"
74+
75+
hclContent1 = `region = "us-east-1"
76+
cores = 2`
77+
hclContent2 = `region = "us-west-2"
78+
go_image = ["1.19","1.20","1.21"]`
79+
jsonContent3 = `{"cat": "foobar", "cores": 3}`
80+
jsonContent4 = `{"dog": 4, "go_image": "[\"1.19\",\"1.20\"]"}`
81+
)
82+
83+
// Prepare the .tfvars files
84+
tempDir, err := os.MkdirTemp(os.TempDir(), "test-parse-variable-values-from-vars-files-*")
85+
require.NoError(t, err)
86+
t.Cleanup(func() {
87+
_ = os.RemoveAll(tempDir)
88+
})
89+
90+
err = os.WriteFile(filepath.Join(tempDir, hclFilename1), []byte(hclContent1), 0o600)
91+
require.NoError(t, err)
92+
err = os.WriteFile(filepath.Join(tempDir, hclFilename2), []byte(hclContent2), 0o600)
93+
require.NoError(t, err)
94+
err = os.WriteFile(filepath.Join(tempDir, jsonFilename3), []byte(jsonContent3), 0o600)
95+
require.NoError(t, err)
96+
err = os.WriteFile(filepath.Join(tempDir, jsonFilename4), []byte(jsonContent4), 0o600)
97+
require.NoError(t, err)
98+
99+
// When
100+
actual, err := cli.ParseUserVariableValues([]string{
101+
filepath.Join(tempDir, hclFilename1),
102+
filepath.Join(tempDir, hclFilename2),
103+
filepath.Join(tempDir, jsonFilename3),
104+
filepath.Join(tempDir, jsonFilename4),
105+
}, "", nil)
106+
require.NoError(t, err)
107+
108+
// Then
109+
expected := []codersdk.VariableValue{
110+
{Name: "cat", Value: "foobar"},
111+
{Name: "cores", Value: "3"},
112+
{Name: "dog", Value: "4"},
113+
{Name: "go_image", Value: "[\"1.19\",\"1.20\"]"},
114+
{Name: "region", Value: "us-west-2"}}
115+
require.Equal(t, expected, actual)
116+
}

0 commit comments

Comments
 (0)