Skip to content

Commit 8ffa10b

Browse files
authored
add plumbing for graph smoke tests (#505)
* fix graph command not working without experiment enabled * oopsy, no space in the json * add plumbing for graph smoke tests
1 parent fe97d98 commit 8ffa10b

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

cmd/dependabot/internal/cmd/graph.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/MakeNowJust/heredoc"
1212
"github.com/dependabot/cli/internal/infra"
13+
"github.com/dependabot/cli/internal/model"
1314
"github.com/spf13/cobra"
1415
)
1516

@@ -66,7 +67,7 @@ func NewGraphCommand() *cobra.Command {
6667
}
6768

6869
if err := infra.Run(infra.RunParams{
69-
Command: infra.UpdateGraphCommand,
70+
Command: model.UpdateGraphCommand,
7071
CacheDir: flags.cache,
7172
CollectorConfigPath: flags.collectorConfigPath,
7273
CollectorImage: collectorImage,

cmd/dependabot/internal/cmd/test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func NewTestCommand() *cobra.Command {
3535
processInput(&smokeTest.Input, nil)
3636

3737
if err := executeTestJob(infra.RunParams{
38+
Command: smokeTest.Command,
3839
CacheDir: flags.cache,
3940
CollectorConfigPath: flags.collectorConfigPath,
4041
CollectorImage: collectorImage,

internal/infra/run.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,16 @@ import (
3030
"gopkg.in/yaml.v3"
3131
)
3232

33-
type RunCommand int
34-
35-
const (
36-
UpdateFilesCommand RunCommand = iota
37-
UpdateGraphCommand
38-
)
39-
40-
var runCmds = map[RunCommand]string{
41-
UpdateFilesCommand: "bin/run fetch_files && bin/run update_files",
42-
UpdateGraphCommand: "bin/run fetch_files && bin/run update_graph",
33+
var runCmds = map[model.RunCommand]string{
34+
model.UpdateFilesCommand: "bin/run fetch_files && bin/run update_files",
35+
model.UpdateGraphCommand: "bin/run fetch_files && bin/run update_graph",
4336
}
4437

4538
type RunParams struct {
4639
// Input file
4740
Input string
4841
// Which command to use, this will default to UpdateFilesCommand
49-
Command RunCommand
42+
Command model.RunCommand
5043
// job definition passed to the updater
5144
Job *model.Job
5245
// expectations asserted at the end of a test
@@ -102,6 +95,10 @@ func (p *RunParams) Validate() error {
10295
if p.Job.Source.Commit != "" && !gitShaRegex.MatchString(p.Job.Source.Commit) {
10396
return fmt.Errorf("commit must be a SHA, or not provided")
10497
}
98+
// Allows for older smoke tests without the command field to keep working.
99+
if p.Command == "" {
100+
p.Command = model.UpdateFilesCommand
101+
}
105102
return nil
106103
}
107104

@@ -177,6 +174,7 @@ func generateOutput(params RunParams, api *server.API, outFile *os.File) ([]byte
177174
// store the SHA we worked with for reproducible tests
178175
params.Job.Source.Commit = api.Actual.Input.Job.Source.Commit
179176
}
177+
api.Actual.Command = params.Command
180178
api.Actual.Input.Job = *params.Job
181179

182180
// ignore conditions help make tests reproducible, so they are generated if there aren't any yet

internal/model/smoke.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package model
22

3+
type RunCommand string
4+
5+
const (
6+
UpdateFilesCommand RunCommand = "update"
7+
UpdateGraphCommand RunCommand = "graph"
8+
)
9+
310
// SmokeTest is a way to test a job by asserting the outputs.
411
type SmokeTest struct {
12+
// Command is the command to run for testing a smoke test (update, graph)
13+
Command RunCommand `yaml:"command"`
514
// Input is the input parameters
615
Input Input `yaml:"input"`
716
// Output is the list of expected outputs

internal/model/update.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type DependencySubmissionRequest struct {
3535
Ref string `json:"ref" yaml:"ref"`
3636
Job map[string]any `json:"job" yaml:"job"`
3737
Detector map[string]any `json:"detector" yaml:"detector"`
38-
Scanned string `json:"scanned" yaml:"scanned"`
3938
Manifests map[string]any `json:"manifests" yaml:"manifests"`
4039
}
4140

internal/server/api.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ func decode[T any](data []byte) (T, error) {
282282
return wrapper.Data, nil
283283
}
284284

285-
// TODO(brrygrdn): Add model.DependencySubmissionRequest to support smoke tests
286-
//
287285
// The test command only expects to run with `update` operations right now so
288286
// we will need to incorporate which run command is expected as well, but we
289287
// don't need regression coverage yet.
290288
func compare(expect, actual *model.UpdateWrapper) error {
291289
switch v := expect.Data.(type) {
290+
case model.DependencySubmissionRequest:
291+
return compareDependencySubmissionRequest(v, actual.Data.(model.DependencySubmissionRequest))
292292
case model.UpdateDependencyList:
293293
return compareUpdateDependencyList(v, actual.Data.(model.UpdateDependencyList))
294294
case model.CreatePullRequest:
@@ -314,6 +314,13 @@ func unexpectedBody(kind string) error {
314314
return fmt.Errorf("unexpected body for %s", kind)
315315
}
316316

317+
func compareDependencySubmissionRequest(expect, actual model.DependencySubmissionRequest) error {
318+
if reflect.DeepEqual(expect, actual) {
319+
return nil
320+
}
321+
return unexpectedBody("dependency_submission_request")
322+
}
323+
317324
func compareUpdateDependencyList(expect, actual model.UpdateDependencyList) error {
318325
if reflect.DeepEqual(expect, actual) {
319326
return nil

testdata/scripts/graph.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# Build the dummy Dockerfile
22
exec docker build -qt graph-updater .
33

4-
# Run the dependabot command
5-
dependabot graph go_modules dependabot/cli --updater-image graph-updater
4+
# Run the graph command and create a smoke test
5+
dependabot graph go_modules dependabot/cli -o out.yml --updater-image graph-updater
66

77
# assert the dummy is working
88
stderr 'bin/run arguments: fetch_files'
99
stderr 'bin/run arguments: update_graph'
1010
stderr '"enable_dependency_submission_poc":true'
1111

12+
# Verify the smoke test can run the graph command
13+
dependabot test -f out.yml --updater-image graph-updater
14+
15+
stderr 'bin/run arguments: fetch_files'
16+
stderr 'bin/run arguments: update_graph'
17+
1218
exec docker rmi -f graph-updater
1319

1420
-- Dockerfile --

0 commit comments

Comments
 (0)