-
Notifications
You must be signed in to change notification settings - Fork 317
feat: Add validation-provider extension capability for preflight checks #8656
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
Open
vhvb1989
wants to merge
13
commits into
main
Choose a base branch
from
extValidate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0b1be95
feat: Add validation-provider extension capability for preflight checks
vhvb1989 70b2d82
fix: address Copilot review feedback (iteration 1)
vhvb1989 1e48f87
fix: address Copilot review feedback (iteration 2)
vhvb1989 b594d87
fix: address Copilot review feedback (iteration 3)
vhvb1989 12c0746
fix: address Copilot review feedback (iteration 4)
vhvb1989 48290c5
fix: address Copilot review feedback (iteration 5)
vhvb1989 b18ded4
fix: address Copilot review feedback (iteration 6)
vhvb1989 b0695ed
fix: address Copilot review feedback (iteration 7)
vhvb1989 cdf87d5
fix: add predicted_resources to context keys in design doc
vhvb1989 6ac5b9e
fix: address Copilot review feedback (iteration 8)
vhvb1989 fc6c736
fix: CI lint/format/spell issues
vhvb1989 f549756
fix: update tests for new validation-provider capability
vhvb1989 a954bd5
test: add coverage for validation-provider packages
vhvb1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
cli/azd/extensions/microsoft.azd.demo/internal/project/demo_validation_check.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package project | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/azdext" | ||
| ) | ||
|
|
||
| // DemoValidationCheck is a sample validation check that always returns | ||
| // a warning to demonstrate the validation-provider capability. | ||
| type DemoValidationCheck struct{} | ||
|
|
||
| // NewDemoValidationCheck creates a new DemoValidationCheck. | ||
| func NewDemoValidationCheck() *DemoValidationCheck { | ||
| return &DemoValidationCheck{} | ||
| } | ||
|
|
||
| // Validate implements azdext.ValidationCheckProvider. | ||
| func (c *DemoValidationCheck) Validate( | ||
| _ context.Context, | ||
| valCtx *azdext.ValidationContext, | ||
| _ *azdext.ValidationCheckRequest, | ||
| ) (*azdext.ValidationCheckResponse, error) { | ||
| msg := "This warning was intentional and generated by the demo extension." | ||
|
|
||
| if resources, err := valCtx.ParsePredictedResources(); err == nil && len(resources) > 0 { | ||
| msg = fmt.Sprintf( | ||
| "%s Bicep snapshot contains %d predicted resources.", | ||
| msg, len(resources), | ||
| ) | ||
| } | ||
|
|
||
| return &azdext.ValidationCheckResponse{ | ||
| Results: []*azdext.ValidationCheckResult{ | ||
| { | ||
| Severity: azdext.ValidationCheckSeverity_VALIDATION_CHECK_SEVERITY_WARNING, | ||
| DiagnosticId: "demo_warning", | ||
| Message: msg, | ||
| }, | ||
| }, | ||
| }, nil | ||
| } |
61 changes: 61 additions & 0 deletions
61
cli/azd/extensions/microsoft.azd.demo/internal/project/demo_validation_check_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package project | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/azdext" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDemoValidationCheck_AlwaysReturnsWarning(t *testing.T) { | ||
| check := NewDemoValidationCheck() | ||
|
|
||
| t.Run("no ARM template", func(t *testing.T) { | ||
| valCtx := &azdext.ValidationContext{ | ||
| ContextID: "test-ctx", | ||
| CheckType: "local-preflight", | ||
| Data: map[string][]byte{}, | ||
| } | ||
| req := &azdext.ValidationCheckRequest{ | ||
| CheckType: "local-preflight", | ||
| RuleId: "demo_warning", | ||
| ContextId: "test-ctx", | ||
| } | ||
|
|
||
| resp, err := check.Validate(t.Context(), valCtx, req) | ||
| require.NoError(t, err) | ||
| require.Len(t, resp.Results, 1) | ||
| require.Equal(t, | ||
| azdext.ValidationCheckSeverity_VALIDATION_CHECK_SEVERITY_WARNING, | ||
| resp.Results[0].Severity, | ||
| ) | ||
| require.Equal(t, | ||
| "This warning was intentional and generated by the demo extension.", | ||
| resp.Results[0].Message, | ||
| ) | ||
| }) | ||
|
|
||
| t.Run("with predicted resources", func(t *testing.T) { | ||
| resourcesJSON := []byte(`[{"type": "a"}, {"type": "b"}, {"type": "c"}]`) | ||
| valCtx := &azdext.ValidationContext{ | ||
| ContextID: "test-ctx-2", | ||
| CheckType: "local-preflight", | ||
| Data: map[string][]byte{ | ||
| azdext.ValidationContextPredictedResources: resourcesJSON, | ||
| }, | ||
| } | ||
| req := &azdext.ValidationCheckRequest{ | ||
| CheckType: "local-preflight", | ||
| RuleId: "demo_warning", | ||
| ContextId: "test-ctx-2", | ||
| } | ||
|
|
||
| resp, err := check.Validate(t.Context(), valCtx, req) | ||
| require.NoError(t, err) | ||
| require.Len(t, resp.Results, 1) | ||
| require.Contains(t, resp.Results[0].Message, "3 predicted resources") | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.