Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d570ce7

Browse files
authored
test(provisioner/terraform): clean up testdata structure (#17074)
1 parent 4e38e6d commit d570ce7

File tree

117 files changed

+26
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+26
-24
lines changed

provisioner/terraform/resources_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func TestConvertResources(t *testing.T) {
863863
expected := expected
864864
t.Run(folderName, func(t *testing.T) {
865865
t.Parallel()
866-
dir := filepath.Join(filepath.Dir(filename), "testdata", folderName)
866+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", folderName)
867867
t.Run("Plan", func(t *testing.T) {
868868
t.Parallel()
869869
ctx, logger := ctxAndLogger(t)
@@ -1021,7 +1021,7 @@ func TestAppSlugValidation(t *testing.T) {
10211021
_, filename, _, _ := runtime.Caller(0)
10221022

10231023
// Load the multiple-apps state file and edit it.
1024-
dir := filepath.Join(filepath.Dir(filename), "testdata", "multiple-apps")
1024+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-apps")
10251025
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-apps.tfplan.json"))
10261026
require.NoError(t, err)
10271027
var tfPlan tfjson.Plan
@@ -1070,7 +1070,7 @@ func TestAppSlugDuplicate(t *testing.T) {
10701070
// nolint:dogsled
10711071
_, filename, _, _ := runtime.Caller(0)
10721072

1073-
dir := filepath.Join(filepath.Dir(filename), "testdata", "multiple-apps")
1073+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-apps")
10741074
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-apps.tfplan.json"))
10751075
require.NoError(t, err)
10761076
var tfPlan tfjson.Plan
@@ -1098,7 +1098,7 @@ func TestAgentNameInvalid(t *testing.T) {
10981098
// nolint:dogsled
10991099
_, filename, _, _ := runtime.Caller(0)
11001100

1101-
dir := filepath.Join(filepath.Dir(filename), "testdata", "multiple-agents")
1101+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-agents")
11021102
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.json"))
11031103
require.NoError(t, err)
11041104
var tfPlan tfjson.Plan
@@ -1147,7 +1147,7 @@ func TestAgentNameDuplicate(t *testing.T) {
11471147
// nolint:dogsled
11481148
_, filename, _, _ := runtime.Caller(0)
11491149

1150-
dir := filepath.Join(filepath.Dir(filename), "testdata", "multiple-agents")
1150+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-agents")
11511151
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.json"))
11521152
require.NoError(t, err)
11531153
var tfPlan tfjson.Plan
@@ -1178,7 +1178,7 @@ func TestMetadataResourceDuplicate(t *testing.T) {
11781178
ctx, logger := ctxAndLogger(t)
11791179

11801180
// Load the multiple-apps state file and edit it.
1181-
dir := filepath.Join("testdata", "resource-metadata-duplicate")
1181+
dir := filepath.Join("testdata", "resources", "resource-metadata-duplicate")
11821182
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "resource-metadata-duplicate.tfplan.json"))
11831183
require.NoError(t, err)
11841184
var tfPlan tfjson.Plan
@@ -1201,7 +1201,7 @@ func TestParameterValidation(t *testing.T) {
12011201
_, filename, _, _ := runtime.Caller(0)
12021202

12031203
// Load the rich-parameters state file and edit it.
1204-
dir := filepath.Join(filepath.Dir(filename), "testdata", "rich-parameters")
1204+
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "rich-parameters")
12051205
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "rich-parameters.tfplan.json"))
12061206
require.NoError(t, err)
12071207
var tfPlan tfjson.Plan

provisioner/terraform/testdata/generate.sh

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4-
cd "$(dirname "${BASH_SOURCE[0]}")"
4+
cd "$(dirname "${BASH_SOURCE[0]}")/resources"
55

66
generate() {
77
local name="$1"
@@ -70,22 +70,17 @@ run() {
7070
cd "$d"
7171
name=$(basename "$(pwd)")
7272

73-
# This needs care to update correctly.
74-
if [[ $name == "kubernetes-metadata" ]]; then
75-
echo "== Skipping: $name"
76-
return 0
77-
fi
78-
79-
# This directory is used for a different purpose (quick workaround).
80-
if [[ $name == "cleanup-stale-plugins" ]]; then
81-
echo "== Skipping: $name"
82-
return 0
83-
fi
84-
85-
if [[ $name == "timings-aggregation" ]]; then
86-
echo "== Skipping: $name"
87-
return 0
88-
fi
73+
toskip=(
74+
# This needs care to update correctly.
75+
"kubernetes-metadata"
76+
)
77+
for skip in "${toskip[@]}"; do
78+
if [[ $name == "$skip" ]]; then
79+
echo "== Skipping: $name"
80+
touch "$name.tfplan.json" "$name.tfplan.dot" "$name.tfstate.json" "$name.tfstate.dot"
81+
return 0
82+
fi
83+
done
8984

9085
echo "== Generating test data for: $name"
9186
if ! out="$(generate "$name" 2>&1)"; then

provisioner/terraform/testdata/presets/presets.tfplan.json renamed to provisioner/terraform/testdata/resources/presets/presets.tfplan.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/presets/presets.tfstate.json renamed to provisioner/terraform/testdata/resources/presets/presets.tfstate.json

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)