diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3b5064e..513ba69 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - go: ["1.25.x", "1.26.x"] + go: ["1.26.x"] os: [ubuntu-24.04, macos-26, windows-2025] steps: diff --git a/.gitignore b/.gitignore index fbba440..e5c265f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin/ tmp/ +vendor/ diff --git a/go.mod b/go.mod index ad3cbb1..d312157 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/AlekSi/hardcache -go 1.25.0 +go 1.26 -toolchain go1.26.3 +toolchain go1.26.5 // https://go.dev/doc/godebug#go-120 // https://pkg.go.dev/archive/tar#Reader.Next @@ -14,15 +14,11 @@ godebug ( require ( github.com/AlekSi/lazyerrors v0.6.0 - github.com/alecthomas/kong v1.15.0 + github.com/AlekSi/shoulda v0.0.0-20260812055123-b29ca4861702 + github.com/alecthomas/kong v1.16.1 github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b - github.com/stretchr/testify v1.11.1 github.com/xhit/go-str2duration/v2 v2.1.0 - golang.org/x/sys v0.44.0 + golang.org/x/sys v0.47.0 ) -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require github.com/sanity-io/litter v1.5.8 // indirect diff --git a/go.sum b/go.sum index 989d45e..2575716 100644 --- a/go.sum +++ b/go.sum @@ -1,35 +1,40 @@ github.com/AlekSi/lazyerrors v0.6.0 h1:TX4iCP7N+YOuOmUl6Gv5OQ7brhPzPPrSsEAm+at+avk= github.com/AlekSi/lazyerrors v0.6.0/go.mod h1:TresBdOmCoC169IDo09YbrYUDXiqRwlLpInBeS1qD2g= +github.com/AlekSi/shoulda v0.0.0-20260812055123-b29ca4861702 h1:fs2UyZ4iZc54wToDRKccJ0YrI92CcOSz6wEcX++gk/g= +github.com/AlekSi/shoulda v0.0.0-20260812055123-b29ca4861702/go.mod h1:2BlJHePkF/aGLNg+T2Zqoa6AzrXFB11MQpFxq4TBK2g= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/kong v1.15.0 h1:BVJstKbpO73zKpmIu+m/aLRrNmWwxXPIGTNin9VmLVI= -github.com/alecthomas/kong v1.15.0/go.mod h1:wrlbXem1CWqUV5Vbmss5ISYhsVPkBb1Yo7YKJghju2I= +github.com/alecthomas/kong v1.16.1 h1:ixhCt93XkJ98kGposQ54+bl0IK6XwqB40AsMynU7Z8E= +github.com/alecthomas/kong v1.16.1/go.mod h1:wrlbXem1CWqUV5Vbmss5ISYhsVPkBb1Yo7YKJghju2I= github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs= github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vSQ6PWWSL9lK8qwHozUj03+zLoEB8O0= github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs= +github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sanity-io/litter v1.5.8 h1:uM/2lKrWdGbRXDrIq08Lh9XtVYoeGtcQxk9rtQ7+rYg= +github.com/sanity-io/litter v1.5.8/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= -golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= -golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/caches/local/disk_test.go b/internal/caches/local/disk_test.go index 4ea15ff..c95e128 100644 --- a/internal/caches/local/disk_test.go +++ b/internal/caches/local/disk_test.go @@ -4,21 +4,21 @@ import ( "os/exec" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/AlekSi/shoulda" + "github.com/AlekSi/shoulda/musta" ) func TestDiskInfo(t *testing.T) { b, err := exec.Command("df", "-m", "/").CombinedOutput() - require.NoError(t, err) + musta.NoError(t, err) t.Logf("\n%s", b) total, free, err := DiskInfo("/") - require.NoError(t, err) + musta.NoError(t, err) t.Logf("\n total: %dM, free: %dM", total/1024/1024, free/1024/1024) - assert.Positive(t, total) - assert.Positive(t, free) - assert.Greater(t, total, free) + shoulda.BeGreater(t, total, 0) + shoulda.BeGreater(t, free, 0) + shoulda.BeGreater(t, total, free) } diff --git a/internal/caches/local/local_test.go b/internal/caches/local/local_test.go index 071febf..29c5067 100644 --- a/internal/caches/local/local_test.go +++ b/internal/caches/local/local_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/AlekSi/shoulda" + "github.com/AlekSi/shoulda/musta" "github.com/AlekSi/hardcache/internal/go/cache" ) @@ -23,7 +23,7 @@ func setup(t testing.TB) string { dst := t.TempDir() b, err := exec.Command("cp", "-a", src, dst).CombinedOutput() - require.NoError(t, err, "%s", b) + musta.NoErrorf(t, err, "%s", b) return filepath.Join(dst, "local") } @@ -45,8 +45,8 @@ func fromHex(t testing.TB, s string) [cache.HashSize]byte { var res [cache.HashSize]byte n, err := hex.Decode(res[:], []byte(s)) - require.NoError(t, err) - require.Equal(t, n, cache.HashSize) + musta.NoError(t, err) + musta.BeEqual(t, n, cache.HashSize) return res } @@ -68,15 +68,13 @@ func TestCache(t *testing.T) { dir := setup(t) - c, err := cache.Open(dir) - require.NoError(t, err) + c := musta.NotFail(cache.Open(dir))(t) t.Cleanup(func() { - require.NoError(t, c.Close()) + musta.NoError(t, c.Close()) }) - actual, err := c.Get(actionID(t, "01a8b978c9044aabe4e554ee2d630f5437162fd385e60fbaf51492b4be15c226")) - require.NoError(t, err) + actual := musta.NotFail(c.Get(actionID(t, "01a8b978c9044aabe4e554ee2d630f5437162fd385e60fbaf51492b4be15c226")))(t) expected := cache.Entry{ OutputID: outputID(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), @@ -84,20 +82,18 @@ func TestCache(t *testing.T) { Time: time.Date(2025, time.November, 17, 17, 13, 1, 426224000, time.UTC).Local(), } - assert.Equal(t, expected.Time, actual.Time) - assert.Equal(t, expected, actual) + shoulda.BeDeepEqual(t, actual.Time, expected.Time) + shoulda.BeDeepEqual(t, actual, expected) - actual, err = c.Get(actionID(t, "fd8792322c0942921f5dca60ae1196d10c2195bfadef68f80f94de000625531c")) - require.NoError(t, err) + actual = musta.NotFail(c.Get(actionID(t, "fd8792322c0942921f5dca60ae1196d10c2195bfadef68f80f94de000625531c")))(t) expected.Time = time.Date(2025, time.November, 17, 17, 13, 2, 227666000, time.UTC).Local() - assert.Equal(t, expected.Time, actual.Time) - assert.Equal(t, expected, actual) + shoulda.BeDeepEqual(t, actual.Time, expected.Time) + shoulda.BeDeepEqual(t, actual, expected) // executable - actual, err = c.Get(actionID(t, "b774285e0fffc3f1827be05e08ea22244e40ae09ca8359e45e329740aaa06dba")) - require.NoError(t, err) + actual = musta.NotFail(c.Get(actionID(t, "b774285e0fffc3f1827be05e08ea22244e40ae09ca8359e45e329740aaa06dba")))(t) expected = cache.Entry{ OutputID: outputID(t, "4b949c7e306fe19cf063f3dc5c1ab963a09a6bea4f7545974fe7385bdbaace94"), @@ -105,90 +101,84 @@ func TestCache(t *testing.T) { Time: time.Date(2025, time.November, 17, 17, 13, 7, 284280000, time.UTC).Local(), } - assert.Equal(t, expected.Time, actual.Time) - assert.Equal(t, expected, actual) + shoulda.BeDeepEqual(t, actual.Time, expected.Time) + shoulda.BeDeepEqual(t, actual, expected) } func TestTrimNoop(t *testing.T) { t.Parallel() c, err := New(setup(t), nil, nil, logger(t)) - require.NoError(t, err) + musta.NoError(t, err) before, freed := c.TrimForce() - assert.EqualValues(t, -1, before) - assert.EqualValues(t, 0, freed) + shoulda.BeEqual(t, before, -1) + shoulda.BeEqual(t, freed, 0) } func TestTrimCutoffNone(t *testing.T) { t.Parallel() cutoff := time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) - c, err := New(setup(t), &cutoff, nil, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), &cutoff, nil, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 0, freed) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(0)) } func TestTrimCutoffAll(t *testing.T) { t.Parallel() cutoff := time.Date(2999, time.January, 1, 0, 0, 0, 0, time.UTC) - c, err := New(setup(t), &cutoff, nil, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), &cutoff, nil, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 109_518_524, freed) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(109_518_524)) } func TestTrimCutoffPart(t *testing.T) { t.Parallel() cutoff := time.Date(2025, time.November, 17, 17, 13, 0, 0, time.UTC) - c, err := New(setup(t), &cutoff, nil, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), &cutoff, nil, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 3_975_344, freed) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(3_975_344)) } func TestTrimSizeNone(t *testing.T) { t.Parallel() maxSize := int64(math.MaxInt64) - c, err := New(setup(t), nil, &maxSize, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), nil, &maxSize, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 0, freed) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(0)) } func TestTrimSizeAll(t *testing.T) { t.Parallel() maxSize := int64(0) - c, err := New(setup(t), nil, &maxSize, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), nil, &maxSize, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 109_518_524, freed) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(109_518_524)) } func TestTrimSizePart(t *testing.T) { t.Parallel() maxSize := int64(50_000_000) - c, err := New(setup(t), nil, &maxSize, logger(t)) - require.NoError(t, err) + c := musta.NotFail(New(setup(t), nil, &maxSize, logger(t)))(t) before, freed := c.TrimForce() - assert.EqualValues(t, 109_518_524, before) - assert.EqualValues(t, 60_023_595, freed) - assert.Less(t, before-freed, maxSize) + shoulda.BeEqual(t, before, int64(109_518_524)) + shoulda.BeEqual(t, freed, int64(60_023_595)) + shoulda.BeLess(t, before-freed, maxSize) } diff --git a/internal/testdata/go.mod b/internal/testdata/go.mod index c7dfaf5..3ccc69b 100644 --- a/internal/testdata/go.mod +++ b/internal/testdata/go.mod @@ -2,6 +2,6 @@ module github.com/AlekSi/hardcache/internal/testdata -go 1.25 +go 1.26 tool github.com/AlekSi/hardcache/internal/testdata/mytool