From 7ce0ebf795d757c62893e60a47a53f07e2efaee0 Mon Sep 17 00:00:00 2001 From: jurre Date: Mon, 12 Oct 2020 14:48:56 +0200 Subject: [PATCH] Gracefully handle gomod package import that has changed When a module exists, but it (no longer) defines the package of a given name, we get an error like such: ``` go: finding module for package github.com/googleapis/gnostic/OpenAPIv2 github.com/dependabot/vgotest imports github.com/googleapis/gnostic/OpenAPIv2: module github.com/googleapis/gnostic@latest found (v0.5.1), but does not contain package github.com/googleapis/gnostic/OpenAPIv2 ``` In this case, we should not treat that as a failed update, but rather as a DependencyFileNotResolvable. --- .../go_modules/file_updater/go_mod_updater.rb | 3 ++- .../file_updater/go_mod_updater_spec.rb | 15 +++++++++++++++ .../spec/fixtures/projects/renamed_package/go.mod | 5 +++++ .../spec/fixtures/projects/renamed_package/go.sum | 9 +++++++++ .../fixtures/projects/renamed_package/main.go | 8 ++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 go_modules/spec/fixtures/projects/renamed_package/go.mod create mode 100644 go_modules/spec/fixtures/projects/renamed_package/go.sum create mode 100644 go_modules/spec/fixtures/projects/renamed_package/main.go diff --git a/go_modules/lib/dependabot/go_modules/file_updater/go_mod_updater.rb b/go_modules/lib/dependabot/go_modules/file_updater/go_mod_updater.rb index 126526c1f5..16ec35a925 100644 --- a/go_modules/lib/dependabot/go_modules/file_updater/go_mod_updater.rb +++ b/go_modules/lib/dependabot/go_modules/file_updater/go_mod_updater.rb @@ -16,7 +16,8 @@ class GoModUpdater RESOLVABILITY_ERROR_REGEXES = [ /go: .*: git fetch .*: exit status 128/.freeze, /verifying .*: checksum mismatch/.freeze, - /build .*: cannot find module providing package/.freeze + /build .*: cannot find module providing package/.freeze, + /module .* found \(.*\), but does not contain package/m.freeze ].freeze MODULE_PATH_MISMATCH_REGEXES = [ diff --git a/go_modules/spec/dependabot/go_modules/file_updater/go_mod_updater_spec.rb b/go_modules/spec/dependabot/go_modules/file_updater/go_mod_updater_spec.rb index 7ebc520277..2cd1e1ecbc 100644 --- a/go_modules/spec/dependabot/go_modules/file_updater/go_mod_updater_spec.rb +++ b/go_modules/spec/dependabot/go_modules/file_updater/go_mod_updater_spec.rb @@ -208,6 +208,21 @@ expect(go_files).to be_empty end end + + context "renamed package name" do + let(:project_name) { "renamed_package" } + let(:dependency_name) { "github.com/googleapis/gnostic" } + # OpenAPIV2 has been renamed to openapiv2 in this version + let(:dependency_version) { "v0.5.1" } + + it "raises a DependencyFileNotResolvable error" do + error_class = Dependabot::DependencyFileNotResolvable + expect { updater.updated_go_sum_content }. + to raise_error(error_class) do |error| + expect(error.message).to include("googleapis/gnostic/OpenAPIv2") + end + end + end end context "without a go.sum" do diff --git a/go_modules/spec/fixtures/projects/renamed_package/go.mod b/go_modules/spec/fixtures/projects/renamed_package/go.mod new file mode 100644 index 0000000000..200b0127af --- /dev/null +++ b/go_modules/spec/fixtures/projects/renamed_package/go.mod @@ -0,0 +1,5 @@ +module github.com/dependabot/vgotest + +go 1.15 + +require github.com/googleapis/gnostic v0.3.1 diff --git a/go_modules/spec/fixtures/projects/renamed_package/go.sum b/go_modules/spec/fixtures/projects/renamed_package/go.sum new file mode 100644 index 0000000000..b5391f79eb --- /dev/null +++ b/go_modules/spec/fixtures/projects/renamed_package/go.sum @@ -0,0 +1,9 @@ +github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk= +github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/go_modules/spec/fixtures/projects/renamed_package/main.go b/go_modules/spec/fixtures/projects/renamed_package/main.go new file mode 100644 index 0000000000..a3877956b0 --- /dev/null +++ b/go_modules/spec/fixtures/projects/renamed_package/main.go @@ -0,0 +1,8 @@ +package main + +import ( + _ "github.com/googleapis/gnostic/OpenAPIv2" +) + +func main() { +}