Skip to content

Commit aa3ef18

Browse files
authored
ignore detector version when testing dependency submission (#523)
1 parent a9245d6 commit aa3ef18

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

internal/server/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ func unexpectedBody(kind string) error {
315315
}
316316

317317
func compareDependencySubmissionRequest(expect, actual model.DependencySubmissionRequest) error {
318+
// since the detector version will change all the time, ignore that in the comparison
319+
tmp := expect.Detector["version"]
320+
defer func() { expect.Detector["version"] = tmp }()
321+
expect.Detector["version"] = actual.Detector["version"]
322+
318323
if reflect.DeepEqual(expect, actual) {
319324
return nil
320325
}

internal/server/api_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"encoding/hex"
88
"encoding/json"
99
"fmt"
10-
"github.com/dependabot/cli/internal/model"
1110
"net/http"
1211
"net/http/httptest"
1312
"testing"
13+
14+
"github.com/dependabot/cli/internal/model"
1415
)
1516

1617
func Test_decodeWrapper(t *testing.T) {
@@ -103,3 +104,28 @@ func TestAPI_CreatePullRequest_ReplacesBinaryWithHash(t *testing.T) {
103104
t.Errorf("expected stdout to contain the original content, got '%s'", stdout.String())
104105
}
105106
}
107+
108+
func TestAPI_compareDependencySubmissionRequest(t *testing.T) {
109+
t.Run("ignores detector version", func(t *testing.T) {
110+
expect := model.DependencySubmissionRequest{
111+
Detector: map[string]any{
112+
"version": "1.2.3",
113+
},
114+
}
115+
actual := model.DependencySubmissionRequest{
116+
Detector: map[string]any{
117+
"version": "4.5.6",
118+
},
119+
}
120+
121+
if compareDependencySubmissionRequest(expect, actual) != nil {
122+
t.Error("expected detector version to be ignored")
123+
}
124+
if expect.Detector["version"] != "1.2.3" {
125+
t.Error("expected expect detector version to be unchanged")
126+
}
127+
if actual.Detector["version"] != "4.5.6" {
128+
t.Error("expected actual detector version to be unchanged")
129+
}
130+
})
131+
}

0 commit comments

Comments
 (0)