From 5136295d91fcabf0bb45438336e4eec8fd6c8ce2 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Thu, 11 Apr 2024 03:47:52 +0200 Subject: [PATCH] Remove github.com/sclevine/spec dependency on tests from monero levin/rpc packages --- go.mod | 1 - go.sum | 2 - monero/client/levin/levin_test.go | 31 ++++++++------- monero/client/levin/portable_storage_test.go | 41 ++++++++++---------- monero/client/rpc/client_test.go | 28 +++++++------ 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/go.mod b/go.mod index 2f5a592..0b7053a 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/floatdrop/lru v1.3.0 github.com/go-zeromq/zmq4 v0.16.1-0.20240124085909-e75c615ba1b3 github.com/goccy/go-json v0.10.2 - github.com/sclevine/spec v1.4.0 github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc golang.org/x/sys v0.19.0 lukechampine.com/uint128 v1.3.0 diff --git a/go.sum b/go.sum index 82bba64..62690a0 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/floatdrop/lru v1.3.0 h1:83abtaKjXcWrPmtzTAk2Ggq8DUKqI29YzrTrB8+vu0c= github.com/floatdrop/lru v1.3.0/go.mod h1:83zlXKA06Bm32JImNINCiTr0ldadvdAjUe5jSwIaw0s= 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/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= -github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= diff --git a/monero/client/levin/levin_test.go b/monero/client/levin/levin_test.go index a29ea20..63be050 100644 --- a/monero/client/levin/levin_test.go +++ b/monero/client/levin/levin_test.go @@ -7,8 +7,6 @@ import ( "testing" "git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin" - "github.com/sclevine/spec" - "github.com/sclevine/spec/report" ) func assertNoError(t *testing.T, err error, msgAndArgs ...any) { @@ -51,9 +49,16 @@ func assertEqual(t *testing.T, actual, expected any, msgAndArgs ...any) { } } +func it(t *testing.T, msg string, f func(t *testing.T)) { + t.Run(msg, func(t *testing.T) { + f(t) + }) +} + func TestLevin(t *testing.T) { - spec.Run(t, "NewHeaderFromBytes", func(t *testing.T, when spec.G, it spec.S) { - it("fails w/ wrong size", func() { + t.Parallel() + t.Run("NewHeaderFromBytes", func(t *testing.T) { + it(t, "fails w/ wrong size", func(t *testing.T) { bytes := []byte{ 0xff, } @@ -62,7 +67,7 @@ func TestLevin(t *testing.T) { assertError(t, err) }) - it("fails w/ wrong signature", func() { + it(t, "fails w/ wrong signature", func(t *testing.T) { bytes := []byte{ 0xff, 0xff, 0xff, 0xff, // signature 0xff, 0xff, 0xff, 0xff, @@ -80,7 +85,7 @@ func TestLevin(t *testing.T) { assertContains(t, err.Error(), "signature mismatch") }) - it("fails w/ invalid command", func() { + it(t, "fails w/ invalid command", func(t *testing.T) { bytes := []byte{ 0x01, 0x21, 0x01, 0x01, // signature 0x01, 0x01, 0x01, 0x01, @@ -98,7 +103,7 @@ func TestLevin(t *testing.T) { assertContains(t, err.Error(), "invalid command") }) - it("fails w/ invalid return code", func() { + it(t, "fails w/ invalid return code", func(t *testing.T) { bytes := []byte{ 0x01, 0x21, 0x01, 0x01, // signature 0x01, 0x01, 0x01, 0x01, @@ -116,7 +121,7 @@ func TestLevin(t *testing.T) { assertContains(t, err.Error(), "invalid return code") }) - it("fails w/ invalid version", func() { + it(t, "fails w/ invalid version", func(t *testing.T) { bytes := []byte{ 0x01, 0x21, 0x01, 0x01, // signature 0x01, 0x01, 0x01, 0x01, @@ -134,7 +139,7 @@ func TestLevin(t *testing.T) { assertContains(t, err.Error(), "invalid version") }) - it("assembles properly from pong", func() { + it(t, "assembles properly from pong", func(t *testing.T) { bytes := []byte{ 0x01, 0x21, 0x01, 0x01, // signature 0x01, 0x01, 0x01, 0x01, @@ -156,8 +161,8 @@ func TestLevin(t *testing.T) { }) }) - spec.Run(t, "NewRequestHeader", func(t *testing.T, when spec.G, it spec.S) { - it("assembles properly w/ ping", func() { + t.Run("NewRequestHeader", func(t *testing.T) { + it(t, "assembles properly w/ ping", func(t *testing.T) { bytes := levin.NewRequestHeader(levin.CommandPing, 1).Bytes() assertEqual(t, bytes, []byte{ @@ -173,7 +178,7 @@ func TestLevin(t *testing.T) { }) }) - it("assembles properly w/ handshake", func() { + it(t, "assembles properly w/ handshake", func(t *testing.T) { bytes := levin.NewRequestHeader(levin.CommandHandshake, 4).Bytes() assertEqual(t, bytes, []byte{ @@ -188,5 +193,5 @@ func TestLevin(t *testing.T) { 0x01, 0x00, 0x00, 0x00, // version }) }) - }, spec.Report(report.Log{}), spec.Parallel(), spec.Random()) + }) } diff --git a/monero/client/levin/portable_storage_test.go b/monero/client/levin/portable_storage_test.go index ffd6447..0848fe4 100644 --- a/monero/client/levin/portable_storage_test.go +++ b/monero/client/levin/portable_storage_test.go @@ -4,13 +4,12 @@ import ( "testing" "git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin" - "github.com/sclevine/spec" - "github.com/sclevine/spec/report" ) func TestPortableStorage(t *testing.T) { - spec.Run(t, "NewPortableStorageFromBytes", func(t *testing.T, when spec.G, it spec.S) { - it("fails w/ wrong sigA", func() { + t.Parallel() + t.Run("NewPortableStorageFromBytes", func(t *testing.T) { + it(t, "fails w/ wrong sigA", func(t *testing.T) { bytes := []byte{ 0xaa, 0xaa, 0xaa, 0xaa, } @@ -20,7 +19,7 @@ func TestPortableStorage(t *testing.T) { assertContains(t, err.Error(), "sig-a doesn't match") }) - it("fails w/ wrong sigB", func() { + it(t, "fails w/ wrong sigB", func(t *testing.T) { bytes := []byte{ 0x01, 0x11, 0x01, 0x01, 0xaa, 0xaa, 0xaa, 0xaa, @@ -31,7 +30,7 @@ func TestPortableStorage(t *testing.T) { assertContains(t, err.Error(), "sig-b doesn't match") }) - it("fails w/ wrong format ver", func() { + it(t, "fails w/ wrong format ver", func(t *testing.T) { bytes := []byte{ 0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, @@ -43,7 +42,7 @@ func TestPortableStorage(t *testing.T) { assertContains(t, err.Error(), "version doesn't match") }) - it("reads the contents", func() { + it(t, "reads the contents", func(t *testing.T) { bytes := []byte{ 0x01, 0x11, 0x01, 0x01, // sig a 0x01, 0x01, 0x02, 0x01, // sig b @@ -97,10 +96,10 @@ func TestPortableStorage(t *testing.T) { }, }) }) - }, spec.Report(report.Log{}), spec.Parallel(), spec.Random()) + }) - spec.Run(t, "ReadVarIn", func(t *testing.T, when spec.G, it spec.S) { - it("i <= 63", func() { + t.Run("ReadVarIn", func(t *testing.T) { + it(t, "i <= 63", func(t *testing.T) { b := []byte{0x08} n, v := levin.ReadVarInt(b) @@ -108,23 +107,23 @@ func TestPortableStorage(t *testing.T) { assertEqual(t, v, 2) }) - it("64 <= i <= 16383", func() { + it(t, "64 <= i <= 16383", func(t *testing.T) { b := []byte{0x01, 0x02} n, v := levin.ReadVarInt(b) assertEqual(t, n, 2) assertEqual(t, v, 128) }) - it("16384 <= i <= 1073741823", func() { + it(t, "16384 <= i <= 1073741823", func(t *testing.T) { b := []byte{0x02, 0x00, 0x01, 0x00} n, v := levin.ReadVarInt(b) assertEqual(t, n, 4) assertEqual(t, v, 16384) }) - }, spec.Report(report.Log{}), spec.Parallel(), spec.Random()) + }) - spec.Run(t, "VarrIn", func(t *testing.T, when spec.G, it spec.S) { - it("i <= 63", func() { + t.Run("VarrIn", func(t *testing.T) { + it(t, "i <= 63", func(t *testing.T) { i := 2 // 0b00000010 b, err := levin.VarIn(i) @@ -134,7 +133,7 @@ func TestPortableStorage(t *testing.T) { }) }) - it("64 <= i <= 16383", func() { + it(t, "64 <= i <= 16383", func(t *testing.T) { i := 128 // 0b010000000 b, err := levin.VarIn(i) @@ -146,7 +145,7 @@ func TestPortableStorage(t *testing.T) { }) }) - it("16384 <= i <= 1073741823", func() { + it(t, "16384 <= i <= 1073741823", func(t *testing.T) { i := 16384 // 1 << 14 b, err := levin.VarIn(i) @@ -155,10 +154,10 @@ func TestPortableStorage(t *testing.T) { 0x02, 0x00, 0x01, 0x00, // (1 << 16) | 2 }) }) - }, spec.Report(report.Log{}), spec.Parallel(), spec.Random()) + }) - spec.Run(t, "PortableStorage", func(t *testing.T, when spec.G, it spec.S) { - it("bytes", func() { + t.Run("PortableStorage", func(t *testing.T) { + it(t, "bytes", func(t *testing.T) { ps := &levin.PortableStorage{ Entries: []levin.Entry{ { @@ -219,5 +218,5 @@ func TestPortableStorage(t *testing.T) { }, ps.Bytes()) }) - }, spec.Report(report.Log{}), spec.Parallel(), spec.Random()) + }) } diff --git a/monero/client/rpc/client_test.go b/monero/client/rpc/client_test.go index de54c52..053cc08 100644 --- a/monero/client/rpc/client_test.go +++ b/monero/client/rpc/client_test.go @@ -11,8 +11,6 @@ import ( "testing" "git.gammaspectra.live/P2Pool/consensus/v3/monero/client/rpc" - "github.com/sclevine/spec" - "github.com/sclevine/spec/report" ) func assertError(t *testing.T, err error, msgAndArgs ...any) { @@ -45,16 +43,24 @@ func assertEqual(t *testing.T, actual, expected any, msgAndArgs ...any) { } } +func it(t *testing.T, msg string, f func(t *testing.T)) { + t.Run(msg, func(t *testing.T) { + f(t) + }) +} + // nolint:funlen func TestClient(t *testing.T) { - spec.Run(t, "JSONRPC", func(t *testing.T, when spec.G, it spec.S) { + t.Parallel() + + t.Run("JSONRPC", func(t *testing.T) { var ( ctx = context.Background() client *rpc.Client err error ) - it("errors when daemon down", func() { + it(t, "errors when daemon down", func(t *testing.T) { daemon := httptest.NewServer(http.HandlerFunc(nil)) daemon.Close() @@ -68,7 +74,7 @@ func TestClient(t *testing.T) { assertContains(t, err.Error(), "do:") }) - it("errors w/ empty response", func() { + it(t, "errors w/ empty response", func(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) {} daemon := httptest.NewServer(http.HandlerFunc(handler)) @@ -84,7 +90,7 @@ func TestClient(t *testing.T) { assertContains(t, err.Error(), "decode") }) - it("errors w/ non-200 response", func() { + it(t, "errors w/ non-200 response", func(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) } @@ -102,7 +108,7 @@ func TestClient(t *testing.T) { assertContains(t, err.Error(), "non-2xx status") }) - it("makes GET request to the jsonrpc endpoint", func() { + it(t, "makes GET request to the jsonrpc endpoint", func(t *testing.T) { var ( endpoint string method string @@ -126,7 +132,7 @@ func TestClient(t *testing.T) { assertEqual(t, method, "GET") }) - it("encodes rpc in request", func() { + it(t, "encodes rpc in request", func(t *testing.T) { var ( body = &rpc.RequestEnvelope{} @@ -158,7 +164,7 @@ func TestClient(t *testing.T) { assertEqual(t, body.Params, params) }) - it("captures result", func() { + it(t, "captures result", func(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, `{"id":"id", "jsonrpc":"jsonrpc", "result": {"foo": "bar"}}`) } @@ -181,7 +187,7 @@ func TestClient(t *testing.T) { assertEqual(t, result, map[string]string{"foo": "bar"}) }) - it("fails if rpc errored", func() { + it(t, "fails if rpc errored", func(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, `{"id":"id", "jsonrpc":"jsonrpc", "error": {"code": -1, "message":"foo"}}`) } @@ -202,5 +208,5 @@ func TestClient(t *testing.T) { assertContains(t, err.Error(), "foo") assertContains(t, err.Error(), "-1") }) - }, spec.Report(report.Terminal{}), spec.Parallel(), spec.Random()) + }) }