зеркало из https://github.com/Azure/azure-dev.git
Add usage snapshot test (#1144)
Adding snapshot tests as coverage for command design changes.
This commit is contained in:
Родитель
600f686fe8
Коммит
ddad650902
|
@ -1,2 +1,3 @@
|
|||
*.go text eol=lf
|
||||
*.snap text eol=lf
|
||||
*.txt text eol=lf
|
|
@ -17,3 +17,4 @@ sethvargo
|
|||
stretchr
|
||||
theckman
|
||||
benbjohnson
|
||||
bradleyjkemp
|
||||
|
|
|
@ -29,6 +29,7 @@ cflags
|
|||
cmdsubst
|
||||
containerapp
|
||||
csharpapp
|
||||
cupaloy
|
||||
devel
|
||||
dockerproject
|
||||
dskip
|
||||
|
@ -70,6 +71,7 @@ rzip
|
|||
semconv
|
||||
serverfarms
|
||||
setenvs
|
||||
snapshotter
|
||||
sstore
|
||||
staticcheck
|
||||
staticwebapp
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd config get <path> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for get.
|
||||
-o, --output string The output format (the supported formats are json). (default "json")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd config list [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for list.
|
||||
-o, --output string The output format (the supported formats are json). (default "json")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Usage:
|
||||
azd config reset [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for reset.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Usage:
|
||||
azd config set <path> <value> [flags]
|
||||
|
||||
Examples:
|
||||
$ azd config set defaults.subscription <yourSubscriptionID>
|
||||
$ azd config set defaults.location eastus
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for set.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Usage:
|
||||
azd config unset <path> [flags]
|
||||
|
||||
Examples:
|
||||
$ azd config unset defaults.location
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for unset.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
Usage:
|
||||
azd config [command]
|
||||
|
||||
Available Commands:
|
||||
get Gets a configuration
|
||||
list Lists all configuration values
|
||||
reset Resets configuration to default
|
||||
set Sets a configuration
|
||||
unset Unsets a configuration
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for config.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd config [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
Usage:
|
||||
azd deploy [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for deploy.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
--service string Deploys a specific service (when the string is unspecified, all services that are listed in the azure.yaml file are deployed).
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Usage:
|
||||
azd down [flags]
|
||||
|
||||
Flags:
|
||||
--force Does not require confirmation before it deletes resources.
|
||||
-h, --help Gets help for down.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
--purge Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd env get-values [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for get-values.
|
||||
-o, --output string The output format (the supported formats are json, dotenv). (default "dotenv")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Usage:
|
||||
azd env list [flags]
|
||||
|
||||
Aliases:
|
||||
list, ls
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for list.
|
||||
-o, --output string The output format (the supported formats are json, table). (default "table")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
Usage:
|
||||
azd env new <environment> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for new.
|
||||
-l, --location string Azure location for the new environment
|
||||
--subscription string Name or ID of an Azure subscription to use for the new environment
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd env refresh [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for refresh.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Usage:
|
||||
azd env select <environment> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for select.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Usage:
|
||||
azd env set <key> <value> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for set.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Usage:
|
||||
azd env [command]
|
||||
|
||||
Available Commands:
|
||||
get-values Get all environment values.
|
||||
list List environments
|
||||
new Create a new environment.
|
||||
refresh Refresh environment settings by using information from a previous infrastructure provision.
|
||||
select Set the default environment.
|
||||
set Set a value in the environment.
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for env.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd env [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Usage:
|
||||
azd infra create [flags]
|
||||
|
||||
Aliases:
|
||||
create, provision
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for create.
|
||||
--no-progress Suppresses progress information.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
Usage:
|
||||
azd infra delete [flags]
|
||||
|
||||
Flags:
|
||||
--force Does not require confirmation before it deletes resources.
|
||||
-h, --help Gets help for delete.
|
||||
--purge Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
Usage:
|
||||
azd infra [command]
|
||||
|
||||
Available Commands:
|
||||
create Create Azure resources for an application.
|
||||
delete Delete Azure resources for an application.
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for infra.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd infra [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Usage:
|
||||
azd init [flags]
|
||||
|
||||
Flags:
|
||||
-b, --branch string The template branch to initialize from.
|
||||
-h, --help Gets help for init.
|
||||
-l, --location string Azure location for the new environment
|
||||
--subscription string Name or ID of an Azure subscription to use for the new environment
|
||||
-t, --template string The template to use when you initialize the project. You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
Usage:
|
||||
azd login [flags]
|
||||
|
||||
Flags:
|
||||
--check-status Checks the log-in status instead of logging in.
|
||||
--client-certificate string The path to the client certificate for the service principal to authenticate with.
|
||||
--client-id string The client id for the service principal to authenticate with.
|
||||
--client-secret string The client secret for the service principal to authenticate with. Set to the empty string to read the value from the console.
|
||||
--federated-credential string The federated token for the service principal to authenticate with. Set to the empty string to read the value from the console.
|
||||
--federated-credential-provider string The provider to use to acquire a federated token to authenticate with.
|
||||
-h, --help Gets help for login.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
--tenant-id string The tenant id for the service principal to authenticate with.
|
||||
--use-device-code When true, log in by using a device code instead of a browser.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Usage:
|
||||
azd logout [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for logout.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Usage:
|
||||
azd monitor [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for monitor.
|
||||
--live Open a browser to Application Insights Live Metrics. Live Metrics is currently not supported for Python applications.
|
||||
--logs Open a browser to Application Insights Logs.
|
||||
--overview Open a browser to Application Insights Overview Dashboard.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Usage:
|
||||
azd pipeline config [flags]
|
||||
|
||||
Flags:
|
||||
--auth-type string The authentication type used between the pipeline provider and Azure for deployment (Only valid for GitHub provider)
|
||||
-h, --help Gets help for config.
|
||||
--principal-name string The name of the service principal to use to grant access to Azure resources as part of the pipeline.
|
||||
--principal-role string The role to assign to the service principal. (default "Contributor")
|
||||
--provider string The pipeline provider to use (GitHub and Azdo supported).
|
||||
--remote-name string The name of the git remote to configure the pipeline to run on. (default "origin")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Usage:
|
||||
azd pipeline [command]
|
||||
|
||||
Available Commands:
|
||||
config Create and configure your deployment pipeline by using GitHub Actions.
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for pipeline.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd pipeline [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
Usage:
|
||||
azd provision [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for provision.
|
||||
--no-progress Suppresses progress information.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd restore [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for restore.
|
||||
--service string Restores a specific service (when the string is unspecified, all services that are listed in the azure.yaml file are restored).
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Usage:
|
||||
azd template list [flags]
|
||||
|
||||
Aliases:
|
||||
list, ls
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for list.
|
||||
-o, --output string The output format (the supported formats are json, table). (default "table")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd template show <template> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for show.
|
||||
-o, --output string The output format (the supported formats are json, table). (default "table")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
Usage:
|
||||
azd template [command]
|
||||
|
||||
Available Commands:
|
||||
list List templates.
|
||||
show Show the template details.
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for template.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd template [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
Usage:
|
||||
azd up [flags]
|
||||
|
||||
Flags:
|
||||
-b, --branch string The template branch to initialize from.
|
||||
-h, --help Gets help for up.
|
||||
-l, --location string Azure location for the new environment
|
||||
--no-progress Suppresses progress information.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
--service string Deploys a specific service (when the string is unspecified, all services that are listed in the azure.yaml file are deployed).
|
||||
--subscription string Name or ID of an Azure subscription to use for the new environment
|
||||
-t, --template string The template to use when you initialize the project. You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Usage:
|
||||
azd version [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help Gets help for version.
|
||||
-o, --output string The output format (the supported formats are json, none). (default "none")
|
||||
|
||||
Global Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
Usage:
|
||||
azd [command]
|
||||
|
||||
Available Commands:
|
||||
config Manage Azure Developer CLI configuration
|
||||
deploy Deploy the application's code to Azure.
|
||||
down Delete Azure resources for an application.
|
||||
env Manage environments.
|
||||
infra Manage Azure resources.
|
||||
init Initialize a new application.
|
||||
login Log in to Azure.
|
||||
logout Log out of Azure
|
||||
monitor Monitor a deployed application.
|
||||
pipeline Manage GitHub Actions pipelines.
|
||||
provision Provision the Azure resources for an application.
|
||||
restore Restore application dependencies.
|
||||
template Manage templates.
|
||||
up Initialize application, provision Azure resources, and deploy your project with a single command.
|
||||
version Print the version number of Azure Developer CLI.
|
||||
|
||||
Flags:
|
||||
-C, --cwd string Sets the current working directory.
|
||||
--debug Enables debugging and diagnostics logging.
|
||||
-e, --environment string The name of the environment to use.
|
||||
-h, --help Gets help for azd.
|
||||
--no-prompt Accepts the default value instead of prompting, or it fails if there is no default.
|
||||
|
||||
Use "azd [command] --help" for more information about a command.
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/azure/azure-dev/cli/azd/test/snapshot"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// To update snapshots (assuming your current directory is cli/azd):
|
||||
//
|
||||
// For Bash,
|
||||
// UPDATE_SNAPSHOTS=true go test ./cmd
|
||||
//
|
||||
// For Pwsh,
|
||||
// $env:UPDATE_SNAPSHOTS='true'; go test ./cmd; $env:UPDATE_SNAPSHOTS=$null
|
||||
func TestUsage(t *testing.T) {
|
||||
root := NewRootCmd()
|
||||
|
||||
usageSnapshot(t, root)
|
||||
}
|
||||
|
||||
func usageSnapshot(t *testing.T, cmd *cobra.Command) {
|
||||
t.Run(cmd.Name(), func(t *testing.T) {
|
||||
snapshot.SnapshotT(t, cmd.UsageString())
|
||||
|
||||
for _, c := range cmd.Commands() {
|
||||
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
||||
continue
|
||||
}
|
||||
|
||||
usageSnapshot(t, c)
|
||||
}
|
||||
})
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Package snapshot contains adapters that azd uses to create snapshot tests.
|
||||
//
|
||||
// Snapshot with default configuration
|
||||
//
|
||||
// func TestExample(t *testing.T) {
|
||||
// result := someFunction()
|
||||
// snapshot.SnapshotT(t, result)
|
||||
// }
|
||||
//
|
||||
// Snapshot with specific file extension
|
||||
//
|
||||
// func TestExample(t *testing.T) {
|
||||
// json := getJson()
|
||||
// snapshotter := snapshot.NewConfig("json")
|
||||
// snapshotter.SnapshotT(t, json)
|
||||
// }
|
||||
//
|
||||
// To update the snapshots simply set the UPDATE_SNAPSHOTS environment variable and run your tests e.g.
|
||||
//
|
||||
// UPDATE_SNAPSHOTS=true go test ./...
|
||||
//
|
||||
// Your snapshot files will now have been updated to reflect the current output of your code.
|
||||
package snapshot
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/bradleyjkemp/cupaloy/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cupaloy.Global = NewDefaultConfig()
|
||||
}
|
||||
|
||||
// NewDefaultConfig creates the default configuration that azd uses.
|
||||
func NewDefaultConfig() *cupaloy.Config {
|
||||
isCi := os.Getenv("GITHUB_ACTIONS") == "true" ||
|
||||
os.Getenv("TF_BUILD") == "True"
|
||||
|
||||
return cupaloy.NewDefaultConfig().
|
||||
// Always use testdata
|
||||
WithOptions(cupaloy.SnapshotSubdirectory("testdata")).
|
||||
// Configure default extension to .snap
|
||||
WithOptions(cupaloy.SnapshotFileExtension(".snap")).
|
||||
// Use go-spew instead of String() and Error() outputs
|
||||
WithOptions(cupaloy.UseStringerMethods(false)).
|
||||
// Fail update on CI, but allow local to succeed
|
||||
WithOptions(cupaloy.FailOnUpdate(isCi))
|
||||
}
|
||||
|
||||
// SnapshotT creates a snapshot with the global config, and the current testing.T.
|
||||
//
|
||||
// SnapshotT compares the given variable to its previous value stored on the filesystem.
|
||||
// test.Fatal is called with the diff if the snapshots do not match, or if a new snapshot was created.
|
||||
//
|
||||
// SnapshotT determines the snapshot file automatically from the name of the test.
|
||||
// As a result it can be called at most once per test.
|
||||
//
|
||||
// If you want to call Snapshot multiple times in a test,
|
||||
// collect the values and call Snapshot with all values at once.
|
||||
func SnapshotT(t *testing.T, i ...interface{}) {
|
||||
cupaloy.SnapshotT(t, i...)
|
||||
}
|
||||
|
||||
// NewConfig creates a new snapshot config with the supplied extension name.
|
||||
//
|
||||
// This can be useful when the snapshot generated is tied to a specific well-known file extension:
|
||||
// json, html, ..., where diff tools will provide better support in diffing the changes.
|
||||
func NewConfig(snapshotExtension string) *cupaloy.Config {
|
||||
return NewDefaultConfig().WithOptions(cupaloy.SnapshotFileExtension(snapshotExtension))
|
||||
}
|
7
go.mod
7
go.mod
|
@ -44,7 +44,12 @@ require (
|
|||
gopkg.in/yaml.v3 v3.0.0
|
||||
)
|
||||
|
||||
require github.com/MakeNowJust/heredoc/v2 v2.0.1
|
||||
require (
|
||||
github.com/MakeNowJust/heredoc/v2 v2.0.1
|
||||
github.com/bradleyjkemp/cupaloy/v2 v2.8.0
|
||||
)
|
||||
|
||||
require github.com/kr/text v0.2.0 // indirect
|
||||
|
||||
require (
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.1 // indirect
|
||||
|
|
6
go.sum
6
go.sum
|
@ -104,6 +104,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
|
|||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
|
||||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
||||
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
|
||||
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
|
@ -130,6 +132,7 @@ github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWH
|
|||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -314,8 +317,9 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
|
|||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
|
||||
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
|
||||
|
|
Загрузка…
Ссылка в новой задаче