Skip to content

Commit

Permalink
[Ubuntu 21.04] Fix test failures in bats tests due to Go 1.16 choosin…
Browse files Browse the repository at this point in the history
…g Go Modules instead of GOPATH by default

* After a system upgrade from `Ubuntu 20.10` to `Ubuntu 21.04`, we noticed an in-house system started failing
  bats tests that used the `go` utility. An example failure symptom is the following.

  ```sh
  $ bats --tap -f TPGC001 bats_tests/test_psql_go_connection.bats
  1..1
  not ok 1 TPGC001 : fetch column data types
  .
  .
  # > go get: malformed module path "get_column_information": missing dot in first path element
  ```

* Thanks to golang/go#35048 (comment), I found the issue and workaround.
  I made a change to do the following before the `go get` that is done in the `run_go()` framework function
  in `tests/test_helpers.bash.in` and `go` related bats tests started working fine then on.

  ```sh
  export GO111MODULE=off
  ```

* https://dev.to/maelvls/why-is-go111module-everywhere-and-everything-about-go-modules-24k discusses this
  issue in detail. Pasted below is the relevant text from there.

  ```
  GO111MODULE with Go 1.16
  ------------------------
  As of Go 1.16, the default behavior is GO111MODULE=on, meaning that if you want to keep using the old
  GOPATH way, you will have to force Go not to use the Go Modules feature:

  export GO111MODULE=off
  ```

* This is exactly what was done at https://gitlab.com/YottaDB/DB/YDBTest/-/merge_requests/1129/diffs too.

* We will need to worry about this when Go 1.17 comes out and everything starts only using `Go Modules`.
  But until then this workaround is good enough.
  • Loading branch information
nars1 committed May 20, 2021
1 parent 069022e commit fba305c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_helpers.bash.in
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ setup_go() {

run_go() {
cp -r @PROJECT_SOURCE_DIR@/tests/go/src/$1 $GOPATH/src/$1
# As of Go 1.16, the default behavior is GO111MODULE=on but we want to keep using the old GOPATH way,
# therefore set the below env var to Go not to use the Go Modules feature. This is not needed by
# Go versions older the Go 1.16 but it does not hurt.
export GO111MODULE=off
go get $1
go build $1
$GOPATH/bin/$1 $2
Expand Down

0 comments on commit fba305c

Please sign in to comment.