-
Notifications
You must be signed in to change notification settings - Fork 261
Extensions integration for figspec and usage snapshot tests #6286
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
JeffreyCA
merged 8 commits into
Azure:main
from
JeffreyCA:jeffreyca/improve-ext-snapshots
Dec 3, 2025
+297
−26
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f9bd61
Use generator for `azd extension show`
JeffreyCA c66ab54
Improve extension support in figspec and usage snapshot tests
JeffreyCA 3160371
Update documentation
JeffreyCA 847250b
Update context handling
JeffreyCA 90d98b6
Test out-of-date figspec
JeffreyCA a0480a2
Test out-of-date usage snapshot
JeffreyCA 361c2d0
Restore snapshots
JeffreyCA c78d858
Update source name
JeffreyCA 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: ext-registry-ci | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "cli/azd/extensions/registry.json" | ||
| - ".github/workflows/ext-registry-ci.yml" | ||
| branches: [main] | ||
|
|
||
| # If two events are triggered within a short time in the same PR, cancel the run of the oldest event | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| snapshot-tests: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: cli/azd | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: "^1.25" | ||
| cache-dependency-path: | | ||
| cli/azd/go.sum | ||
|
|
||
| - name: Build azd | ||
| run: go build . | ||
|
|
||
| - name: Run FigSpec snapshot test | ||
| run: go test ./cmd -v -run TestFigSpec | ||
|
|
||
| - name: Run Usage snapshot test | ||
| run: go test ./cmd -v -run TestUsage | ||
|
|
||
| - name: Check snapshot test results | ||
| if: failure() | ||
| run: | | ||
| echo "::error::Snapshots may be out of date. Run the following locally to update them:" | ||
| echo "" | ||
| echo " cd cli/azd" | ||
| echo " UPDATE_SNAPSHOTS=true go test ./cmd -run 'TestFigSpec|TestUsage'" | ||
| exit 1 |
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,85 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/test/azdcli" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| const ( | ||
| localSourceName = "local" | ||
| ) | ||
|
|
||
| // extensionListEntry represents an extension entry returned from the extension list command. | ||
| type extensionListEntry struct { | ||
| ID string `json:"id"` | ||
| Version string `json:"version"` | ||
| Source string `json:"source"` | ||
| } | ||
|
|
||
| func installAllExtensions(ctx context.Context, t *testing.T, cli *azdcli.CLI, sourceName string) { | ||
| t.Helper() | ||
|
|
||
| result, err := cli.RunCommand(ctx, "extension", "list", "--source", sourceName, "--output", "json") | ||
| require.NoError(t, err, "failed to list extensions from source %s", sourceName) | ||
|
|
||
| var extensions []extensionListEntry | ||
| err = json.Unmarshal([]byte(result.Stdout), &extensions) | ||
| require.NoError(t, err, "failed to unmarshal extension list") | ||
|
|
||
| if len(extensions) == 0 { | ||
| t.Logf("No extensions found in source %s to install", sourceName) | ||
| return | ||
| } | ||
|
|
||
| for _, ext := range extensions { | ||
| args := []string{"extension", "install", ext.ID, "--source", sourceName} | ||
| if ext.Version != "" { | ||
| args = append(args, "--version", ext.Version) | ||
| } | ||
|
|
||
| t.Logf("Installing extension %s@%s", ext.ID, ext.Version) | ||
| _, err := cli.RunCommand(ctx, args...) | ||
| require.NoErrorf(t, err, "failed to install extension %s from source %s", ext.ID, sourceName) | ||
| } | ||
| } | ||
|
|
||
| func uninstallAllExtensions(ctx context.Context, t *testing.T, cli *azdcli.CLI) { | ||
| t.Helper() | ||
|
|
||
| t.Log("Uninstalling all extensions") | ||
| if _, err := cli.RunCommand(ctx, "extension", "uninstall", "--all"); err != nil { | ||
| t.Logf("warning: failed to uninstall extensions: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func addLocalRegistrySource(ctx context.Context, t *testing.T, cli *azdcli.CLI) string { | ||
| t.Helper() | ||
|
|
||
| registryPath := filepath.Join(azdcli.GetSourcePath(), "extensions", "registry.json") | ||
| t.Logf("Adding local registry source '%s' from %s", localSourceName, registryPath) | ||
| _, err := cli.RunCommand( | ||
| ctx, | ||
| "extension", "source", "add", | ||
| "-n", localSourceName, | ||
| "-t", "file", | ||
| "-l", registryPath, | ||
| ) | ||
| require.NoError(t, err, "failed to add local registry source") | ||
| return localSourceName | ||
| } | ||
|
|
||
| func removeLocalExtensionSource(ctx context.Context, t *testing.T, cli *azdcli.CLI) { | ||
| t.Helper() | ||
|
|
||
| if _, err := cli.RunCommand(ctx, "extension", "source", "remove", localSourceName); err != nil { | ||
| t.Logf("warning: failed to remove extension source %s: %v", localSourceName, err) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
|
|
||
| This extension provides examples of the AZD extension framework. | ||
|
|
||
| Usage | ||
| azd demo [flags] | ||
|
|
||
| Global Flags | ||
| -C, --cwd string : Sets the current working directory. | ||
| --debug : Enables debugging and diagnostics logging. | ||
| --docs : Opens the documentation for azd demo in your web browser. | ||
| -h, --help : Gets help for demo. | ||
| --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. | ||
|
|
||
| Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. | ||
|
|
||
|
|
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
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.