Skip to content

feat: allow for default presets #18445

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

Merged
merged 13 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: generate test fixtures correctly
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
  • Loading branch information
dannykopping committed Jun 19, 2025
commit f0f77fb9129c68af2bd9ee27c802dce0e3d134eb
20 changes: 5 additions & 15 deletions provisioner/terraform/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ func TestDefaultPresets(t *testing.T) {

// nolint:dogsled
_, filename, _, _ := runtime.Caller(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, non-blocking: I understand that this is copied from other tests, but I wonder if we could use t.Name() instead?

dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "presets")
dir := filepath.Join(filepath.Dir(filename), "testdata", "resources")

cases := map[string]struct {
fixtureFile string
Expand All @@ -1323,12 +1323,12 @@ func TestDefaultPresets(t *testing.T) {
validate func(t *testing.T, state *terraform.State)
}{
"multiple defaults should fail": {
fixtureFile: "multiple-defaults",
fixtureFile: "presets-multiple-defaults",
expectError: true,
errorMsg: "a maximum of 1 coder_workspace_preset can be marked as default, but 2 are set",
},
"single default should succeed": {
fixtureFile: "single-default",
fixtureFile: "presets-single-default",
expectError: false,
validate: func(t *testing.T, state *terraform.State) {
require.Len(t, state.Presets, 2)
Expand All @@ -1342,16 +1342,6 @@ func TestDefaultPresets(t *testing.T) {
require.Equal(t, 1, defaultCount)
},
},
"no defaults should succeed": {
fixtureFile: "no-defaults",
expectError: false,
validate: func(t *testing.T, state *terraform.State) {
require.Len(t, state.Presets, 2)
for _, preset := range state.Presets {
require.False(t, preset.Default)
}
},
},
}

for name, tc := range cases {
Expand All @@ -1360,12 +1350,12 @@ func TestDefaultPresets(t *testing.T) {
t.Parallel()
ctx, logger := ctxAndLogger(t)

tfPlanRaw, err := os.ReadFile(filepath.Join(dir, tc.fixtureFile+".tfplan.json"))
tfPlanRaw, err := os.ReadFile(filepath.Join(dir, tc.fixtureFile, tc.fixtureFile+".tfplan.json"))
require.NoError(t, err)
var tfPlan tfjson.Plan
err = json.Unmarshal(tfPlanRaw, &tfPlan)
require.NoError(t, err)
tfPlanGraph, err := os.ReadFile(filepath.Join(dir, tc.fixtureFile+".tfplan.dot"))
tfPlanGraph, err := os.ReadFile(filepath.Join(dir, tc.fixtureFile, tc.fixtureFile+".tfplan.dot"))
require.NoError(t, err)

modules := []*tfjson.StateModule{tfPlan.PlannedValues.RootModule}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.3.0-pre2"
version = ">= 2.3.0"
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading