Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unit tests fail on 32-bit archs #644

Open
dswarbrick opened this issue Dec 17, 2024 · 3 comments
Open

[Bug]: Unit tests fail on 32-bit archs #644

dswarbrick opened this issue Dec 17, 2024 · 3 comments
Labels
bug issues that report a bug

Comments

@dswarbrick
Copy link

go Version

go version go1.23.2 linux/amd64

API Wrapper Version

github.com/linode/linodego v1.43.0

Code Snippet

n/a

Expected Behavior

Test should pass successfully on all supported Go archs.

Actual Behavior

Unit tests failed to build on 32-bit archs due to untyped int overflows.

$ GOARCH=386 go test ./unit
# github.com/linode/linodego/test/unit [github.com/linode/linodego/test/unit.test]
unit/instance_test.go:92:18: cannot use 30471077120 (untyped int constant) as int value in argument to assert.Equal (overflows)
unit/instance_test.go:93:18: cannot use 22956600198 (untyped int constant) as int value in argument to assert.Equal (overflows)
unit/instance_test.go:94:18: cannot use 53427677318 (untyped int constant) as int value in argument to assert.Equal (overflows)
FAIL    github.com/linode/linodego/test/unit [build failed]
FAIL

Steps to Reproduce

Run tests with a 32-bit GOARCH, e.g. "386".

@dswarbrick dswarbrick added the bug issues that report a bug label Dec 17, 2024
@dswarbrick
Copy link
Author

dswarbrick commented Dec 17, 2024

Note that merely casting the untyped int constants in the unit test to int64 is not a viable solution either, since many of the underlying structs specify members as untyped ints, e.g.

// MonthlyInstanceTransferStats pool stats for a Linode Instance network transfer statistics for a specific month
type MonthlyInstanceTransferStats struct {
    // The amount of inbound public network traffic received by this Linode, in bytes, for a specific year/month.
    BytesIn int `json:"bytes_in"`

    // The amount of outbound public network traffic sent by this Linode, in bytes, for a specific year/month.
    BytesOut int `json:"bytes_out"`

    // The total amount of public network traffic sent and received by this Linode, in bytes, for a specific year/month.
    BytesTotal int `json:"bytes_total"`
}

These are highly likely to overflow when used on 32-bit archs, and really ought to be specified as int64 or even better, uint64. I expect it's not uncommon for instances to transmit or receive more than 2.1 GB in a month.

2024/12/17 16:10:09 [INFO] Received error  - Retrying
2024/12/17 16:10:12.079183 WARN RESTY Put "https://api.linode.com/v4/profile": http2: server sent GOAWAY and closed the connection; LastStreamID=0, ErrCode=NO_ERROR, debug="", Attempt 1
2024/12/17 16:10:12 [INFO] Received error  - Retrying
Stats: &{Title:linode.com - my-linode (linode123456) - day (5 min avg) Data:{CPU:[[1.5214836e+12 0.42]] IO:{IO:[[1.5214848e+12 0.19]] Swap:[[1.5214848e+12 0]]} NetV4:{In:[[1.5214848e+12 2004.36]] Out:[[1.5214848e+12 3928.91]] PrivateIn:[[1.5214848e+12 0]] PrivateOut:[[1.5214848e+12 5.6]]} NetV6:{In:[[1.5214848e+12 0]] Out:[[1.5214848e+12 0]] PrivateIn:[[1.5214848e+12 195.18]] PrivateOut:[[1.5214848e+12 5.6]]}}}
2024/12/17 16:10:15.087377 WARN RESTY json: cannot unmarshal number 30471077120 into Go struct field MonthlyInstanceTransferStats.bytes_in of type int, Attempt 1
2024/12/17 16:10:15.087409 ERROR RESTY json: cannot unmarshal number 30471077120 into Go struct field MonthlyInstanceTransferStats.bytes_in of type int
--- FAIL: TestInstance_Get_MonthlyTransfer (0.00s)
    instance_test.go:88: 
                Error Trace:    /home/daniel/Work/Debian/golang-github-linode-linodego/test/unit/instance_test.go:88
                Error:          Received unexpected error:
                                [002] json: cannot unmarshal number 30471077120 into Go struct field MonthlyInstanceTransferStats.bytes_in of type int
                Test:           TestInstance_Get_MonthlyTransfer

As it stands, this library really is not suitable for use on 32-bit archs, yet it would have been trivial to make it so.

@dswarbrick
Copy link
Author

Related PR #605.

@zliang-akamai
Copy link
Member

@dswarbrick thanks for reporting this issue to us! We will discuss it and get back to you shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues that report a bug
Projects
None yet
Development

No branches or pull requests

2 participants