diff --git a/core/codec/gzip_test.go b/core/codec/gzip_test.go index 29a89748..b73be8fe 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 9f798e41..f7265465 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 49d28725..e58a66a4 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 7ce2b58f..3b30c31b 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 fec847d5..cf4c90cf 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 99f356b8..22799374 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 5bdde8b5..5d386857 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 b0fd1c54..280ac945 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 3d5e135c..58752a83 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 5a97ff27..6e4e0bd5 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 3ab80b6a..ecdd45ec 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 7ad70cec..1274d19f 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 437cbcf5..6851cff8 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 14dc240b..aaae7a7f 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 9afb2940..ede5b43f 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 e53c7e31..bfa3c8b6 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 0e95afb3..3a9a84a9 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 1a0a5636..5b220549 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 700f0f09..b9c27ff7 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 8c269513..6d752100 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 676b88c2..380d94a2 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 d5f2d543..b2eefe87 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 47968f1e..7421d34e 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 6ca6533d..09564796 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 e451de4c..e67fd8c0 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