diff --git a/core/codec/gzip_test.go b/core/codec/gzip_test.go index 29a897481..b73be8fef 100644 --- a/core/codec/gzip_test.go +++ b/core/codec/gzip_test.go @@ -2,6 +2,8 @@ package codec import ( "bytes" + "compress/gzip" + "errors" "fmt" "testing" @@ -21,3 +23,45 @@ func TestGzip(t *testing.T) { assert.True(t, len(bs) < buf.Len()) assert.Equal(t, buf.Bytes(), actual) } + +func TestGunzip(t *testing.T) { + tests := []struct { + name string + input []byte + expected []byte + expectedErr error + }{ + { + name: "valid input", + input: func() []byte { + var buf bytes.Buffer + gz := gzip.NewWriter(&buf) + gz.Write([]byte("hello")) + gz.Close() + return buf.Bytes() + }(), + expected: []byte("hello"), + expectedErr: nil, + }, + { + name: "invalid input", + input: []byte("invalid input"), + expected: nil, + expectedErr: gzip.ErrHeader, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + result, err := Gunzip(test.input) + + if !bytes.Equal(result, test.expected) { + t.Errorf("unexpected result: %v", result) + } + + if !errors.Is(err, test.expectedErr) { + t.Errorf("unexpected error: %v", err) + } + }) + } +} diff --git a/core/fs/files+polyfill.go b/core/fs/files+polyfill.go index 9f798e41e..f72654656 100644 --- a/core/fs/files+polyfill.go +++ b/core/fs/files+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package fs diff --git a/core/fs/files.go b/core/fs/files.go index 49d287259..e58a66a4b 100644 --- a/core/fs/files.go +++ b/core/fs/files.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package fs diff --git a/core/mr/mapreduce_fuzzcase_test.go b/core/mr/mapreduce_fuzzcase_test.go index 7ce2b58f7..3b30c31b1 100644 --- a/core/mr/mapreduce_fuzzcase_test.go +++ b/core/mr/mapreduce_fuzzcase_test.go @@ -1,5 +1,4 @@ //go:build fuzz -// +build fuzz package mr diff --git a/core/proc/goroutines+polyfill.go b/core/proc/goroutines+polyfill.go index fec847d53..cf4c90cff 100644 --- a/core/proc/goroutines+polyfill.go +++ b/core/proc/goroutines+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package proc diff --git a/core/proc/goroutines.go b/core/proc/goroutines.go index 99f356b8c..22799374f 100644 --- a/core/proc/goroutines.go +++ b/core/proc/goroutines.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package proc diff --git a/core/proc/profile+polyfill.go b/core/proc/profile+polyfill.go index 5bdde8b5f..5d3868577 100644 --- a/core/proc/profile+polyfill.go +++ b/core/proc/profile+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package proc diff --git a/core/proc/profile.go b/core/proc/profile.go index b0fd1c546..280ac945d 100644 --- a/core/proc/profile.go +++ b/core/proc/profile.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package proc diff --git a/core/proc/shutdown+polyfill.go b/core/proc/shutdown+polyfill.go index 3d5e135cb..58752a835 100644 --- a/core/proc/shutdown+polyfill.go +++ b/core/proc/shutdown+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package proc diff --git a/core/proc/shutdown.go b/core/proc/shutdown.go index 5a97ff272..6e4e0bd5c 100644 --- a/core/proc/shutdown.go +++ b/core/proc/shutdown.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package proc diff --git a/core/proc/shutdown_test.go b/core/proc/shutdown_test.go index 3ab80b6a8..ecdd45ec5 100644 --- a/core/proc/shutdown_test.go +++ b/core/proc/shutdown_test.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package proc diff --git a/core/proc/signals+polyfill.go b/core/proc/signals+polyfill.go index 7ad70cecf..1274d19f9 100644 --- a/core/proc/signals+polyfill.go +++ b/core/proc/signals+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package proc diff --git a/core/proc/signals.go b/core/proc/signals.go index 437cbcf54..6851cff81 100644 --- a/core/proc/signals.go +++ b/core/proc/signals.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package proc diff --git a/core/search/tree_debug.go b/core/search/tree_debug.go index 14dc240bb..aaae7a7fe 100644 --- a/core/search/tree_debug.go +++ b/core/search/tree_debug.go @@ -1,5 +1,4 @@ //go:build debug -// +build debug package search diff --git a/core/stat/alert+polyfill.go b/core/stat/alert+polyfill.go index 9afb29409..ede5b43fd 100644 --- a/core/stat/alert+polyfill.go +++ b/core/stat/alert+polyfill.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux package stat diff --git a/core/stat/alert.go b/core/stat/alert.go index e53c7e311..bfa3c8b67 100644 --- a/core/stat/alert.go +++ b/core/stat/alert.go @@ -1,5 +1,4 @@ //go:build linux -// +build linux package stat diff --git a/core/stat/alert_test.go b/core/stat/alert_test.go index 0e95afb38..3a9a84a9f 100644 --- a/core/stat/alert_test.go +++ b/core/stat/alert_test.go @@ -1,5 +1,4 @@ //go:build linux -// +build linux package stat diff --git a/core/stat/internal/cgroup_linux.go b/core/stat/internal/cgroup_linux.go index 1a0a5636e..5b2205494 100644 --- a/core/stat/internal/cgroup_linux.go +++ b/core/stat/internal/cgroup_linux.go @@ -278,10 +278,8 @@ func runningInUserNS() bool { var a, b, c int64 fmt.Sscanf(line, "%d %d %d", &a, &b, &c) - /* - * We assume we are in the initial user namespace if we have a full - * range - 4294967295 uids starting at uid 0. - */ + // We assume we are in the initial user namespace if we have a full + // range - 4294967295 uids starting at uid 0. if a == 0 && b == 0 && c == 4294967295 { return } diff --git a/core/stat/internal/cpu_other.go b/core/stat/internal/cpu_other.go index 700f0f098..b9c27ff75 100644 --- a/core/stat/internal/cpu_other.go +++ b/core/stat/internal/cpu_other.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux package internal diff --git a/core/stringx/node_fuzz_test.go b/core/stringx/node_fuzz_test.go index 8c269513d..6d752100d 100644 --- a/core/stringx/node_fuzz_test.go +++ b/core/stringx/node_fuzz_test.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package stringx import ( diff --git a/core/utils/version_test.go b/core/utils/version_test.go index 676b88c2a..380d94a22 100644 --- a/core/utils/version_test.go +++ b/core/utils/version_test.go @@ -15,8 +15,10 @@ func TestCompareVersions(t *testing.T) { out bool }{ {"1", "1.0.1", ">", false}, + {"1.0.1", "1.0", "<", false}, {"1", "0.9.9", ">", true}, {"1", "1.0-1", "<", true}, + {"1", "1.0-1", "!", false}, {"1.0.1", "1-0.1", "<", false}, {"1.0.1", "1.0.1", "==", true}, {"1.0.1", "1.0.2", "==", false}, @@ -37,3 +39,21 @@ func TestCompareVersions(t *testing.T) { }) } } + +func TestStrsToInts(t *testing.T) { + testCases := []struct { + input []string + expected []int64 + }{ + {[]string{}, nil}, + {[]string{"1", "2", "3"}, []int64{1, 2, 3}}, + } + + for _, tc := range testCases { + tc := tc + t.Run("", func(t *testing.T) { + actual := strsToInts(tc.input) + assert.Equal(t, tc.expected, actual) + }) + } +} diff --git a/tools/goctl/migrate/cancel+polyfill.go b/tools/goctl/migrate/cancel+polyfill.go index d5f2d543a..b2eefe87a 100644 --- a/tools/goctl/migrate/cancel+polyfill.go +++ b/tools/goctl/migrate/cancel+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package migrate diff --git a/tools/goctl/migrate/cancel.go b/tools/goctl/migrate/cancel.go index 47968f1e7..7421d34ea 100644 --- a/tools/goctl/migrate/cancel.go +++ b/tools/goctl/migrate/cancel.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package migrate diff --git a/tools/goctl/util/pathx/readlink+polyfill.go b/tools/goctl/util/pathx/readlink+polyfill.go index 6ca6533df..09564796c 100644 --- a/tools/goctl/util/pathx/readlink+polyfill.go +++ b/tools/goctl/util/pathx/readlink+polyfill.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package pathx diff --git a/tools/goctl/util/pathx/readlink.go b/tools/goctl/util/pathx/readlink.go index e451de4ca..e67fd8c03 100644 --- a/tools/goctl/util/pathx/readlink.go +++ b/tools/goctl/util/pathx/readlink.go @@ -1,5 +1,4 @@ //go:build linux || darwin -// +build linux darwin package pathx