Skip to content

Commit

Permalink
CHERRY-PICK: revcache: remove goconvey
Browse files Browse the repository at this point in the history
Remove use of goconvey from private/revcache, replacing it with the
default go testrunner with subtests and stretchr/testify/assert.

Remove some unused functions instead of updating their tests.

Completely aside: change NewKey to return a Key by value instead of a
reference. It is used as value everywhere and it just hurt my eyes.

Fixes scionproto#3016
  • Loading branch information
matzf authored and lukedirtwalker committed Sep 3, 2024
1 parent fe96ca5 commit 60958e5
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 355 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require (
github.com/prometheus/procfs v0.14.0
github.com/quic-go/quic-go v0.43.1
github.com/sergi/go-diff v1.3.1
github.com/smartystreets/goconvey v1.8.1
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -78,14 +77,12 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
Expand All @@ -110,7 +107,6 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/smarty/assertions v1.16.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 h1:velgFPYr1X9TDwLIfk
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
Expand All @@ -131,8 +129,6 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF
github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down Expand Up @@ -239,10 +235,6 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smarty/assertions v1.16.0 h1:EvHNkdRA4QHMrn75NZSoUQ/mAUXAYWfatfB01yTCzfY=
github.com/smarty/assertions v1.16.0/go.mod h1:duaaFdCS0K9dnoM50iyek/eYINOZ64gbh1Xlf6LG7AI=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down
54 changes: 0 additions & 54 deletions go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,6 @@ def go_deps():
sum = "h1:zC34cGQu69FG7qzJ3WiKW244WfhDC3xxYMeNOX2gtUQ=",
version = "v0.0.0-20210719221736-1c9a4c676720",
)
go_repository(
name = "com_github_gopherjs_gopherjs",
importpath = "github.com/gopherjs/gopherjs",
sum = "h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=",
version = "v1.17.2",
)
go_repository(
name = "com_github_gorilla_css",
importpath = "github.com/gorilla/css",
Expand Down Expand Up @@ -721,12 +715,6 @@ def go_deps():
sum = "h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=",
version = "v1.1.12",
)
go_repository(
name = "com_github_jtolds_gls",
importpath = "github.com/jtolds/gls",
sum = "h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=",
version = "v4.20.0+incompatible",
)
go_repository(
name = "com_github_juju_gnuflag",
importpath = "github.com/juju/gnuflag",
Expand Down Expand Up @@ -1027,18 +1015,6 @@ def go_deps():
sum = "h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=",
version = "v0.1.9",
)
go_repository(
name = "com_github_neelance_astrewrite",
importpath = "github.com/neelance/astrewrite",
sum = "h1:D6paGObi5Wud7xg83MaEFyjxQB1W5bz5d0IFppr+ymk=",
version = "v0.0.0-20160511093645-99348263ae86",
)
go_repository(
name = "com_github_neelance_sourcemap",
importpath = "github.com/neelance/sourcemap",
sum = "h1:bY6ktFuJkt+ZXkX0RChQch2FtHpWQLVS8Qo1YasiIVk=",
version = "v0.0.0-20200213170602-2833bce08e4c",
)
go_repository(
name = "com_github_niemeyer_pretty",
importpath = "github.com/niemeyer/pretty",
Expand Down Expand Up @@ -1213,42 +1189,12 @@ def go_deps():
sum = "h1:KkH3I3sJuOLP3TjA/dfr4NAY8bghDwnXiU7cTKxQqo0=",
version = "v0.0.0-20220729165902-8cddb4f5de06",
)
go_repository(
name = "com_github_shurcool_go",
importpath = "github.com/shurcooL/go",
sum = "h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ=",
version = "v0.0.0-20200502201357-93f07166e636",
)
go_repository(
name = "com_github_shurcool_httpfs",
importpath = "github.com/shurcooL/httpfs",
sum = "h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=",
version = "v0.0.0-20190707220628-8d4bc4ba7749",
)
go_repository(
name = "com_github_shurcool_vfsgen",
importpath = "github.com/shurcooL/vfsgen",
sum = "h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=",
version = "v0.0.0-20200824052919-0d455de96546",
)
go_repository(
name = "com_github_sirupsen_logrus",
importpath = "github.com/sirupsen/logrus",
sum = "h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=",
version = "v1.8.1",
)
go_repository(
name = "com_github_smarty_assertions",
importpath = "github.com/smarty/assertions",
sum = "h1:EvHNkdRA4QHMrn75NZSoUQ/mAUXAYWfatfB01yTCzfY=",
version = "v1.16.0",
)
go_repository(
name = "com_github_smartystreets_goconvey",
importpath = "github.com/smartystreets/goconvey",
sum = "h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=",
version = "v1.8.1",
)
go_repository(
name = "com_github_songgao_water",
importpath = "github.com/songgao/water",
Expand Down
2 changes: 1 addition & 1 deletion private/revcache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ go_test(
"//pkg/segment:go_default_library",
"//private/revcache/mock_revcache:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
)
1 change: 0 additions & 1 deletion private/revcache/memrevcache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ go_test(
"//pkg/private/ctrl/path_mgmt:go_default_library",
"//private/revcache:go_default_library",
"//private/revcache/revcachetest:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
],
)
6 changes: 1 addition & 5 deletions private/revcache/memrevcache/memrevcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/pkg/private/ctrl/path_mgmt"
"github.com/scionproto/scion/private/revcache"
"github.com/scionproto/scion/private/revcache/revcachetest"
Expand Down Expand Up @@ -54,7 +52,5 @@ func (c *testRevCache) Prepare(t *testing.T, _ context.Context) {
}

func TestRevCacheSuite(t *testing.T) {
Convey("RevCache Suite", t, func() {
revcachetest.TestRevCache(t, &testRevCache{memRevCache: New()})
})
revcachetest.TestRevCache(t, &testRevCache{memRevCache: New()})
}
51 changes: 3 additions & 48 deletions private/revcache/revcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Key struct {
}

// NewKey creates a new key for the revocation cache.
func NewKey(ia addr.IA, ifId common.IFIDType) *Key {
return &Key{
func NewKey(ia addr.IA, ifId common.IFIDType) Key {
return Key{
IA: ia,
IfId: ifId,
}
Expand All @@ -48,7 +48,7 @@ type KeySet map[Key]struct{}

// SingleKey is a convenience function to return a KeySet with a single key.
func SingleKey(ia addr.IA, ifId common.IFIDType) KeySet {
return KeySet{*NewKey(ia, ifId): {}}
return KeySet{Key{IA: ia, IfId: ifId}: {}}
}

// RevOrErr is either a revocation or an error.
Expand Down Expand Up @@ -86,48 +86,3 @@ type RevCache interface {

// Revocations is the map of revocations.
type Revocations map[Key]*path_mgmt.RevInfo

// RevocationToMap converts a slice of revocations to a revocation map. If extracting the info field
// fails from a revocation, nil and the error is returned.
func RevocationToMap(revs []*path_mgmt.RevInfo) (Revocations, error) {
res := make(Revocations)
for _, rev := range revs {
res[Key{IA: rev.IA(), IfId: rev.IfID}] = rev
}
return res, nil
}

// Keys returns the set of keys in this revocation map.
func (r Revocations) Keys() KeySet {
keys := make(KeySet, len(r))
for key := range r {
keys[key] = struct{}{}
}
return keys
}

// ToSlice extracts the values from this revocation map.
func (r Revocations) ToSlice() []*path_mgmt.RevInfo {
res := make([]*path_mgmt.RevInfo, 0, len(r))
for _, rev := range r {
res = append(res, rev)
}
return res
}

// FilterNew drops all revocations in r that are already in the revCache.
func (r Revocations) FilterNew(ctx context.Context, revCache RevCache) error {
inCache, err := revCache.Get(ctx, r.Keys())
if err != nil {
return err
}
for key, rev := range r {
existingRev, exists := inCache[key]
if exists {
if !newerInfo(existingRev, rev) {
delete(r, key)
}
}
}
return nil
}
1 change: 0 additions & 1 deletion private/revcache/revcachetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ go_library(
"//pkg/private/util:go_default_library",
"//pkg/private/xtest:go_default_library",
"//private/revcache:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
Expand Down
Loading

0 comments on commit 60958e5

Please sign in to comment.