vultr / govultr

Vultr Go API client
MIT License
232 stars 56 forks source link

[BUG] - Go test fails due to int overflows on 32 bits arches #147

Open eclipseo opened 3 years ago

eclipseo commented 3 years ago

While running the tests on 32 bits arches such at armv!7hl and i686, the following errors occur:

Testing    in: /builddir/build/BUILD/govultr-2.5.1/_build/src
         PATH: /builddir/build/BUILD/govultr-2.5.1/_build/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/govultr-2.5.1/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags " -X github.com/vultr/govultr/v2/version=2.5.1 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  '"
      testing: github.com/vultr/govultr/v2
github.com/vultr/govultr/v2
# github.com/vultr/govultr/v2 [github.com/vultr/govultr/v2.test]
./backup_test.go:50:4: constant 42949672960 overflows int
./backup_test.go:145:3: constant 42949672960 overflows int
./bare_metal_server_test.go:65:3: constant 2199756823533 overflows int
./bare_metal_server_test.go:306:4: constant 2199756823533 overflows int
./snapshot_test.go:33:3: constant 42949672960 overflows int
./snapshot_test.go:62:3: constant 42949672960 overflows int
./snapshot_test.go:91:3: constant 42949672960 overflows int
./snapshot_test.go:136:4: constant 42949672960 overflows int
FAIL    github.com/vultr/govultr/v2 [build failed]
dswarbrick commented 1 year ago

The overflows in backup_test.go and snapshot_test.go are fairly self-explanatory, as the Backup and Snapshot structs use an untyped int for the Size member. This should be changed to an int64, or even better, uint64 if there is no need to hold "magic" negative values.

The bare_metal_test.go is a bit more of an odd one. The Go struct is using an untyped int to hold a MAC address, as the Vultr API apparently returns it as such, e.g. "mac_address": 2199756823533. Since ethernet MAC addresses are 48-bit, and most of them will have bits set in the "high" bytes, I would expect a very large majority of MAC addresses to overflow a 32-bit int.

A custom JSON unmarshaller would handle this more elegantly, and unmarshal the address into a Go https://pkg.go.dev/net#HardwareAddr.