Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Caches into one version #2

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 11 additions & 43 deletions cache/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,29 @@ 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,
},
}

// 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)
}
Expand Down Expand Up @@ -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",
}

Expand Down
13 changes: 1 addition & 12 deletions cache/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 0 additions & 35 deletions cache/go.sum
Original file line number Diff line number Diff line change
@@ -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=
8 changes: 0 additions & 8 deletions cache/lookaside/go.mod

This file was deleted.

4 changes: 0 additions & 4 deletions cache/lookaside/go.sum

This file was deleted.

Loading