[GODRIVER-2834] Ensure `build` task fails on broken import. Created: 05/May/23  Updated: 27/Oct/23  Resolved: 10/May/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: release-improvements
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Scope

  • Ensure build task fails on broken import.

Background & Motivation

The 1.11.5 release had a failure on `go mod tidy`:

❯ go get go.mongodb.org/mongo-driver@latest
go: downloading go.mongodb.org/mongo-driver v1.11.5
go: upgraded go.mongodb.org/mongo-driver v1.10.3 => v1.11.5
❯ go mod tidy
go: finding module for package go.mongodb.org/mongo-driver/internal/assert
loadtest imports
        go.mongodb.org/mongo-driver/mongo/options tested by
        go.mongodb.org/mongo-driver/mongo/options.test imports
        go.mongodb.org/mongo-driver/internal/assert: module go.mongodb.org/mongo-driver@latest found (v1.11.5), but does not contain package go.mongodb.org/mongo-driver/internal/assert

The last build task passed, despite commands in the task failing:

[2023/05/02 21:21:00.912] can't load test package: mongo/options/changestreamoptions_test.go:6:2: cannot find module providing package go.mongodb.org/mongo-driver/internal/assert: import lookup disabled by -mod=readonly
[2023/05/02 21:21:00.912]     (Go version in go.mod is 1.13, so vendor directory was not used.)

To reproduce: check out the commit e01fa5c76ee2cc9ba9f30ddcd79d046e503a0423, which included the broken test build that impacted 1.11.5. Run this script:

function assert_eq () {
    a="$1"
    b="$2"
    if [[ "$a" != "$b" ]]; then
        echo "Assertion failed: $a != $b"
        # Print caller
        caller
        exit 1
    fi
}
 
go test -c ./mongo/options > /dev/null 2>&1
# Expect `go test` to exit with error code.
assert_eq $? 1
 
make build-tests > /dev/null 2>&1
# Expect `make build-tests` to exit with error code.
assert_eq $? 1
# Results in: `Assertion failed: 0 != 1`


Generated at Thu Feb 08 08:39:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.