Skip to content

Commit 176b0c5

Browse files
committed
fix test
1 parent e65bdd7 commit 176b0c5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

preview.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (o Output) MarshalJSON() ([]byte, error) {
7474
//
7575
// This will only validate presets that have prebuilds configured and have no existing
7676
// error diagnostics.
77-
func ValidatePrebuilds(ctx context.Context, input Input, preValid []types.Preset, dir fs.FS) []types.Preset {
77+
func ValidatePrebuilds(ctx context.Context, input Input, preValid []types.Preset, dir fs.FS) {
7878
for i := range preValid {
7979
pre := &preValid[i]
8080
if pre.Prebuild == nil || pre.Prebuild.Instances <= 0 {
@@ -87,16 +87,21 @@ func ValidatePrebuilds(ctx context.Context, input Input, preValid []types.Preset
8787
continue
8888
}
8989

90+
// Diagnostics are added to the existing preset.
9091
input.ParameterValues = pre.Parameters
9192
output, diagnostics := Preview(ctx, input, dir)
9293
if diagnostics.HasErrors() {
9394
pre.Diagnostics = append(pre.Diagnostics, diagnostics...)
95+
// Do not pile on more diagnostics for individual params, it already failed
96+
continue
9497
}
9598

9699
if output == nil {
97100
continue
98101
}
99102

103+
// If any parameter is invalid, then the preset is invalid.
104+
// A value must be specified for this failing parameter.
100105
for _, param := range output.Parameters {
101106
if hcl.Diagnostics(param.Diagnostics).HasErrors() {
102107
for _, paramDiag := range param.Diagnostics {
@@ -110,7 +115,6 @@ func ValidatePrebuilds(ctx context.Context, input Input, preValid []types.Preset
110115
}
111116
}
112117
}
113-
return preValid
114118
}
115119

116120
func Preview(ctx context.Context, input Input, dir fs.FS) (output *Output, diagnostics hcl.Diagnostics) {

preview_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ func Test_Extract(t *testing.T) {
716716

717717
for _, preset := range output.Presets {
718718
check, ok := tc.presets[preset.Name]
719+
if !ok && tc.presetsFuncs != nil {
720+
// TODO: Convert presetsFunc to presets
721+
continue
722+
}
719723
require.True(t, ok, "unknown preset %s", preset.Name)
720724
check(t, preset)
721725
}

0 commit comments

Comments
 (0)