From 4db0017813983af8f93a541e71a136612b46440e Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Fri, 1 Aug 2025 08:02:43 -0500 Subject: [PATCH] rename "scenario" to "smoke test" for clarity --- README.md | 28 +++++++++---------- cmd/dependabot/internal/cmd/test.go | 34 +++++++++++------------ cmd/dependabot/internal/cmd/test_test.go | 4 +-- cmd/dependabot/internal/cmd/update.go | 2 +- internal/infra/run.go | 4 +-- internal/infra/run_test.go | 4 +-- internal/model/{scenario.go => smoke.go} | 4 +-- internal/server/api.go | 4 +-- testdata/basic.yml | 6 ++++ testdata/{scenario.yml => smoke-test.yml} | 0 10 files changed, 47 insertions(+), 43 deletions(-) rename internal/model/{scenario.go => smoke.go} (88%) rename testdata/{scenario.yml => smoke-test.yml} (100%) diff --git a/README.md b/README.md index fd9798ea..615e6bfa 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Examples: Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command - test Test scenarios + test Run a smoke test update Perform an update job Flags: @@ -189,11 +189,11 @@ such as when evaluating manifest files or executing install scripts. ### `dependabot test` Run the `test` subcommand -with a scenario file specified by the `--file` / `-f` option +with a smoke test file specified by the `--file` / `-f` option to test the expected behavior for a Dependabot update job. ```console -$ dependabot test -f scenario.yaml +$ dependabot test -f smoke-test.yaml # ... +------------------------------------------+ | Changes to Dependabot Pull Requests | @@ -204,14 +204,12 @@ $ dependabot test -f scenario.yaml time="2022-09-28T08:15:26Z" level=info msg="15/15 calls cached (100%)" ``` - +### Smoke test -### Scenario file - -A scenario file describes the input and expected output of a Dependabot job. +A smoke test describes the input _and_ expected output of a Dependabot job. ```yaml -# scenario.yaml +# smoke-test.yaml input: job: package-manager: docker @@ -249,7 +247,7 @@ output: version: "22.04" ``` -This example scenario describes the expected behavior for Dependabot +This example smoke test describes the expected behavior for Dependabot to update the base image of a Dockerfile from `ubuntu:17.04` to `ubuntu:22.04`. * The `input` field consists of a `job` and any `credentials`. @@ -260,24 +258,24 @@ to update the base image of a Dockerfile from `ubuntu:17.04` to `ubuntu:22.04`. > **Note** > -> The scenario file format isn't documented publicly, +> The smoke test format isn't documented publicly, > but you can find examples in the [`smoke-tests` repo][smoke-tests] > and check [the `Job` class in `dependabot-core`][dependabot-updater-job]. ### Producing a test -To produce a scenario file that tests Dependabot behavior for a given repo, +To produce a smoke test that tests Dependabot behavior for a given repo, run the `update` subcommand and set the `--output` / `-o` option to a file path. ```console -dependabot update go_modules dependabot/cli -o go-scenario.yml +dependabot update go_modules dependabot/cli -o go-smoke-test.yml ``` -Run the `test` subcommand for the generated scenario file, +Run the `test` subcommand for the generated smoke test, specifying a cache directory with the `--cache` option. ```console -dependabot test -f go-scenario.yml --cache ./tmp/cache +dependabot test -f go-smoke-test.yml --cache ./tmp/cache ``` While performing the update job, @@ -288,7 +286,7 @@ and you should see a line that looks like this at the bottom of the output: > time="2022-09-28T08:14:01Z" level=info msg="117/117 calls cached (100%)" -When the cache coverage for a scenario is 100%, +When the cache coverage for a smoke test is 100%, subsequent runs of the `test` subcommand are most likely to be fast and deterministic. Any cache misses indicate an external request made by the updater, diff --git a/cmd/dependabot/internal/cmd/test.go b/cmd/dependabot/internal/cmd/test.go index 387488d7..a5a0e6df 100644 --- a/cmd/dependabot/internal/cmd/test.go +++ b/cmd/dependabot/internal/cmd/test.go @@ -20,31 +20,31 @@ func NewTestCommand() *cobra.Command { var flags SharedFlags cmd := &cobra.Command{ - Use: "test -f ", - Short: "Test scenarios", + Use: "test -f ", + Short: "Run a smoke test", RunE: func(cmd *cobra.Command, args []string) error { if flags.file == "" { - return fmt.Errorf("requires a scenario file") + return fmt.Errorf("requires a smoke test file to run, use -f ") } - scenario, inputRaw, err := readScenarioFile(flags.file) + smokeTest, inputRaw, err := readSmokeTest(flags.file) if err != nil { return err } - processInput(&scenario.Input, nil) + processInput(&smokeTest.Input, nil) if err := executeTestJob(infra.RunParams{ CacheDir: flags.cache, CollectorConfigPath: flags.collectorConfigPath, CollectorImage: collectorImage, - Creds: scenario.Input.Credentials, + Creds: smokeTest.Input.Credentials, Debug: flags.debugging, - Expected: scenario.Output, + Expected: smokeTest.Output, ExtraHosts: flags.extraHosts, InputName: flags.file, InputRaw: inputRaw, - Job: &scenario.Input.Job, + Job: &smokeTest.Input.Job, LocalDir: flags.local, Output: flags.output, ProxyCertPath: flags.proxyCertPath, @@ -62,9 +62,9 @@ func NewTestCommand() *cobra.Command { }, } - cmd.Flags().StringVarP(&flags.file, "file", "f", "", "path to scenario file") + cmd.Flags().StringVarP(&flags.file, "file", "f", "", "path to the smoke test") - cmd.Flags().StringVarP(&flags.output, "output", "o", "", "write scenario to file") + cmd.Flags().StringVarP(&flags.output, "output", "o", "", "write a smoke test to file") cmd.Flags().StringVar(&flags.cache, "cache", "", "cache import/export directory") cmd.Flags().StringVar(&flags.local, "local", "", "local directory to use as fetched source") cmd.Flags().StringVar(&flags.proxyCertPath, "proxy-cert", "", "path to a certificate the proxy will trust") @@ -80,20 +80,20 @@ func NewTestCommand() *cobra.Command { var testCmd = NewTestCommand() -func readScenarioFile(file string) (*model.Scenario, []byte, error) { - var scenario model.Scenario +func readSmokeTest(file string) (*model.SmokeTest, []byte, error) { + var smokeTest model.SmokeTest data, err := os.ReadFile(file) if err != nil { - return nil, nil, fmt.Errorf("failed to open scenario file: %w", err) + return nil, nil, fmt.Errorf("failed to open smoke test: %w", err) } - if err = json.Unmarshal(data, &scenario); err != nil { - if err = yaml.Unmarshal(data, &scenario); err != nil { - return nil, nil, fmt.Errorf("failed to decode scenario file: %w", err) + if err = json.Unmarshal(data, &smokeTest); err != nil { + if err = yaml.Unmarshal(data, &smokeTest); err != nil { + return nil, nil, fmt.Errorf("failed to decode smoke test: %w", err) } } - return &scenario, data, nil + return &smokeTest, data, nil } func init() { diff --git a/cmd/dependabot/internal/cmd/test_test.go b/cmd/dependabot/internal/cmd/test_test.go index 872f221b..f5c0d607 100644 --- a/cmd/dependabot/internal/cmd/test_test.go +++ b/cmd/dependabot/internal/cmd/test_test.go @@ -10,14 +10,14 @@ func TestTestCommand(t *testing.T) { executeTestJob = infra.Run }) - t.Run("Read a scenario file", func(t *testing.T) { + t.Run("Read a smoke test file", func(t *testing.T) { var actualParams *infra.RunParams executeTestJob = func(params infra.RunParams) error { actualParams = ¶ms return nil } cmd := NewTestCommand() - err := cmd.ParseFlags([]string{"-f", "../../../../testdata/scenario.yml"}) + err := cmd.ParseFlags([]string{"-f", "../../../../testdata/smoke-test.yml"}) if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/cmd/dependabot/internal/cmd/update.go b/cmd/dependabot/internal/cmd/update.go index d3aa11b8..3fa12d4d 100644 --- a/cmd/dependabot/internal/cmd/update.go +++ b/cmd/dependabot/internal/cmd/update.go @@ -121,7 +121,7 @@ func NewUpdateCommand() *cobra.Command { cmd.Flags().StringVarP(&flags.commit, "commit", "", "", "commit to update") cmd.Flags().StringArrayVarP(&flags.dependencies, "dep", "", nil, "dependencies to update") - cmd.Flags().StringVarP(&flags.output, "output", "o", "", "write scenario to file") + cmd.Flags().StringVarP(&flags.output, "output", "o", "", "write a smoke test file") cmd.Flags().StringVar(&flags.cache, "cache", "", "cache import/export directory") cmd.Flags().StringVar(&flags.local, "local", "", "local directory to use as fetched source") cmd.Flags().StringVar(&flags.proxyCertPath, "proxy-cert", "", "path to a certificate the proxy will trust") diff --git a/internal/infra/run.go b/internal/infra/run.go index 1157fb5c..d4d23020 100644 --- a/internal/infra/run.go +++ b/internal/infra/run.go @@ -137,7 +137,7 @@ func Run(params RunParams) error { } // run the containers, but don't return the error until AFTER the output is generated. - // this ensures that the output is always written in the scenario where there are multiple outputs, + // this ensures that the output is always written in the smoke test where there are multiple outputs, // some that succeed and some that fail; we still want to see the output of the successful ones. runContainersErr := runContainers(ctx, params) @@ -322,7 +322,7 @@ func expandEnvironmentVariables(api *server.API, params *RunParams) { } } -func generateIgnoreConditions(params *RunParams, actual *model.Scenario) error { +func generateIgnoreConditions(params *RunParams, actual *model.SmokeTest) error { for _, out := range actual.Output { if out.Type == "create_pull_request" { createPR, ok := out.Expect.Data.(model.CreatePullRequest) diff --git a/internal/infra/run_test.go b/internal/infra/run_test.go index 6cf52c1e..2de66a52 100644 --- a/internal/infra/run_test.go +++ b/internal/infra/run_test.go @@ -109,7 +109,7 @@ func Test_generateIgnoreConditions(t *testing.T) { Output: outputFileName, } v := "1.0.0" - actual := &model.Scenario{ + actual := &model.SmokeTest{ Output: []model.Output{{ Type: "create_pull_request", Expect: model.UpdateWrapper{Data: model.CreatePullRequest{ @@ -140,7 +140,7 @@ func Test_generateIgnoreConditions(t *testing.T) { runParams := &RunParams{ Output: outputFileName, } - actual := &model.Scenario{ + actual := &model.SmokeTest{ Output: []model.Output{{ Type: "create_pull_request", Expect: model.UpdateWrapper{Data: model.CreatePullRequest{ diff --git a/internal/model/scenario.go b/internal/model/smoke.go similarity index 88% rename from internal/model/scenario.go rename to internal/model/smoke.go index 47cf1c39..3bf6e8fc 100644 --- a/internal/model/scenario.go +++ b/internal/model/smoke.go @@ -1,7 +1,7 @@ package model -// Scenario is a way to test a job by asserting the outputs. -type Scenario struct { +// SmokeTest is a way to test a job by asserting the outputs. +type SmokeTest struct { // Input is the input parameters Input Input `yaml:"input"` // Output is the list of expected outputs diff --git a/internal/server/api.go b/internal/server/api.go index a154a30e..c2bb5bac 100644 --- a/internal/server/api.go +++ b/internal/server/api.go @@ -28,8 +28,8 @@ type API struct { Expectations []model.Output // Errors is the error list populated by doing a Dependabot run Errors []error - // Actual will contain the scenario output that actually happened after the run is Complete - Actual model.Scenario + // Actual will contain the smoke test output that actually happened after the run is Complete + Actual model.SmokeTest server *http.Server cursor int diff --git a/testdata/basic.yml b/testdata/basic.yml index ca821c57..4bcc56b4 100644 --- a/testdata/basic.yml +++ b/testdata/basic.yml @@ -7,3 +7,9 @@ job: provider: github repo: dependabot/cli directory: / +credentials: + - type: git_source + host: github.com + username: x-access-token + password: $LOCAL_GITHUB_ACCESS_TOKEN + diff --git a/testdata/scenario.yml b/testdata/smoke-test.yml similarity index 100% rename from testdata/scenario.yml rename to testdata/smoke-test.yml