From e07b10e4a53d4a4a05dfffcdd717250dfb633f3d Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sun, 7 Jul 2024 06:44:07 -0700 Subject: [PATCH] Merging Caches into one version --- cache/common_test.go | 54 +++++++++--------------------------------- cache/go.mod | 13 +--------- cache/go.sum | 35 --------------------------- cache/lookaside/go.mod | 8 ------- cache/lookaside/go.sum | 4 ---- 5 files changed, 12 insertions(+), 102 deletions(-) delete mode 100644 cache/lookaside/go.mod delete mode 100644 cache/lookaside/go.sum diff --git a/cache/common_test.go b/cache/common_test.go index 9e01d36..eb7dd7e 100644 --- a/cache/common_test.go +++ b/cache/common_test.go @@ -6,46 +6,16 @@ import ( "time" "github.com/tarmac-project/hord" - "github.com/tarmac-project/hord/drivers/cassandra" "github.com/tarmac-project/hord/drivers/hashmap" - "github.com/tarmac-project/hord/drivers/redis" ) -func DialFromName(name string) (hord.Database, error) { - switch name { - case "cassandra": - return cassandra.Dial(cassandra.Config{ - Hosts: []string{"cassandra-primary", "cassandra"}, - Keyspace: "hord", - }) - case "hashmap": - return hashmap.Dial(hashmap.Config{}) - case "redis": - return redis.Dial(redis.Config{ - ConnectTimeout: time.Duration(5) * time.Second, - Server: "redis:6379", - }) - default: - return nil, fmt.Errorf("Unknown Database Type") - } -} - func TestInterfaceHappyPath(t *testing.T) { // Setup Configurations cfgs := map[string]struct { - cacheType string - dbType string cacheMethod Type }{ - "Redis + Cassandra": { - cacheType: "redis", - dbType: "cassandra", - cacheMethod: Lookaside, - }, - "Redis + Hashmap": { - cacheType: "redis", - dbType: "hashmap", + "Lookaside Caching": { cacheMethod: Lookaside, }, } @@ -53,13 +23,12 @@ func TestInterfaceHappyPath(t *testing.T) { // Loop through valid Configs and validate the driver adheres to the Hord interface for name, cfg := range cfgs { t.Run(name, func(t *testing.T) { - // Dial Dependent Databases - cache, err := DialFromName(cfg.cacheType) + cache, err := hashmap.Dial(hashmap.Config{}) if err != nil { t.Fatalf("Failed to connect to cache - %s", err) } - database, err := DialFromName(cfg.dbType) + database, err := hashmap.Dial(hashmap.Config{}) if err != nil { t.Fatalf("Failed to connect to database - %s", err) } @@ -306,30 +275,29 @@ func TestInterfaceHappyPath(t *testing.T) { } func TestInterfaceFail(t *testing.T) { - // Setup Redis, Cassandra Test Databases - redis, err := DialFromName("redis") + cache, err := hashmap.Dial(hashmap.Config{}) if err != nil { - t.Fatalf("Failed to connect to Redis - %s", err) + t.Fatalf("Failed to connect to Hashmap - %s", err) } - cass, err := DialFromName("cassandra") + database, err := hashmap.Dial(hashmap.Config{}) if err != nil { - t.Fatalf("Failed to connect to Cassandra - %s", err) + t.Fatalf("Failed to connect to Hashmap - %s", err) } // Setup Invalid Configurations cfgs := make(map[string]Config) cfgs["Missing Cache"] = Config{ - Database: cass, + Database: database, Type: Lookaside, } cfgs["Missing Database"] = Config{ - Cache: redis, + Cache: cache, Type: Lookaside, } cfgs["Invalid Type"] = Config{ - Cache: redis, - Database: cass, + Cache: cache, + Database: database, Type: "invalid", } diff --git a/cache/go.mod b/cache/go.mod index fe933d6..ffdafc8 100644 --- a/cache/go.mod +++ b/cache/go.mod @@ -4,19 +4,8 @@ go 1.20 require ( github.com/tarmac-project/hord v0.5.0 - github.com/tarmac-project/hord/cache/lookaside v0.5.0 - github.com/tarmac-project/hord/drivers/cassandra v0.5.0 github.com/tarmac-project/hord/drivers/hashmap v0.5.0 github.com/tarmac-project/hord/drivers/mock v0.5.0 - github.com/tarmac-project/hord/drivers/redis v0.5.0 ) -require ( - github.com/FZambia/sentinel v1.1.1 // indirect - github.com/gocql/gocql v1.6.0 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/gomodule/redigo v1.9.2 // indirect - github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect - gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/cache/go.sum b/cache/go.sum index c967b1c..5a2b555 100644 --- a/cache/go.sum +++ b/cache/go.sum @@ -1,45 +1,10 @@ -github.com/FZambia/sentinel v1.1.1 h1:0ovTimlR7Ldm+wR15GgO+8C2dt7kkn+tm3PQS+Qk3Ek= -github.com/FZambia/sentinel v1.1.1/go.mod h1:ytL1Am/RLlAoAXG6Kj5LNuw/TRRQrv2rt2FT26vP5gI= -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -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/gocql/gocql v1.6.0 h1:IdFdOTbnpbd0pDhl4REKQDM+Q0SzKXQ1Yh+YZZ8T/qU= -github.com/gocql/gocql v1.6.0/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s= -github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw= -github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= -github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/tarmac-project/hord v0.5.0 h1:jIhq0szOyj2q+SMXA6o4pAR4NJVY9NKKr3Ow7bKfPnA= github.com/tarmac-project/hord v0.5.0/go.mod h1:b46vLVFfL9G/WG5BYNTNoordvQ9wQ+ibs1/Fn4v0vkE= -github.com/tarmac-project/hord/cache/lookaside v0.5.0 h1:XRf5y2dqUA2BklfOxq/FIGmf6B7JrrbG3YdwaVM//Io= -github.com/tarmac-project/hord/cache/lookaside v0.5.0/go.mod h1:9ogdDBqBPeqKukNXysgxUzD5+NjSLRsEd1MCJZKrHuk= -github.com/tarmac-project/hord/drivers/cassandra v0.5.0 h1:IxAUhDo7alilpl1nVxpmqL3M8ZLg4NWMH2oo1tJYK4s= -github.com/tarmac-project/hord/drivers/cassandra v0.5.0/go.mod h1:cpwYD+DEayp4tX+LjrySmuH7o6iYAHCLjE1Z/D0USxc= github.com/tarmac-project/hord/drivers/hashmap v0.5.0 h1:tMkwh52N0oIYP4jHobHpte2f4rg2OceJVb9DDK6ER/Y= github.com/tarmac-project/hord/drivers/hashmap v0.5.0/go.mod h1:Dy4kCdSwpbdI8vtkz+05s50UDAVb780M7YKWr/3FLNs= github.com/tarmac-project/hord/drivers/mock v0.5.0 h1:CV/OYlKE+i/MsMYyG+jhT0aN+T8nFWKkaTqsaFedZ30= github.com/tarmac-project/hord/drivers/mock v0.5.0/go.mod h1:fTnYOoMJjRa+i38Z2gS7ADCzXVmQNWI2YDUq2Ym/sNk= -github.com/tarmac-project/hord/drivers/redis v0.5.0 h1:NeqZuuuXIJ7mVYcc9DfDxQEHg8JoDNKlv1QYPeDxP0I= -github.com/tarmac-project/hord/drivers/redis v0.5.0/go.mod h1:IkEyKT6x0v5JJanm2utnNdfT8gu3dhDvuR9bbe8pEHE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= -gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/cache/lookaside/go.mod b/cache/lookaside/go.mod deleted file mode 100644 index dd39d5d..0000000 --- a/cache/lookaside/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/tarmac-project/hord/cache/lookaside - -go 1.20 - -require ( - github.com/tarmac-project/hord v0.5.0 - github.com/tarmac-project/hord/drivers/mock v0.5.0 -) diff --git a/cache/lookaside/go.sum b/cache/lookaside/go.sum deleted file mode 100644 index ff5e6ee..0000000 --- a/cache/lookaside/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/tarmac-project/hord v0.5.0 h1:jIhq0szOyj2q+SMXA6o4pAR4NJVY9NKKr3Ow7bKfPnA= -github.com/tarmac-project/hord v0.5.0/go.mod h1:b46vLVFfL9G/WG5BYNTNoordvQ9wQ+ibs1/Fn4v0vkE= -github.com/tarmac-project/hord/drivers/mock v0.5.0 h1:CV/OYlKE+i/MsMYyG+jhT0aN+T8nFWKkaTqsaFedZ30= -github.com/tarmac-project/hord/drivers/mock v0.5.0/go.mod h1:fTnYOoMJjRa+i38Z2gS7ADCzXVmQNWI2YDUq2Ym/sNk=