This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
// "fmt" | ||
"github.com/fzzy/radix/extra/pool" | ||
"github.com/fzzy/radix/redis" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
"testing" | ||
) | ||
|
||
// Set up the suite for running tests with Redis | ||
type Suite struct { | ||
suite.Suite | ||
} | ||
|
||
func (suite *Suite) SetupTest() { | ||
var err error | ||
df := func(network, addr string) (*redis.Client, error) { | ||
client, err := redis.Dial(network, addr) | ||
// fmt.Println("DIaling") | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = client.Cmd("SELECT", 8).Err | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = client.Cmd("FLUSHDB").Err | ||
if err != nil { | ||
return nil, err | ||
} | ||
return client, nil | ||
} | ||
redisPool, err = pool.NewCustomPool("tcp", redisURL, 1, df) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func TestSuite(t *testing.T) { | ||
suite.Run(t, new(Suite)) | ||
} | ||
|
||
func (suite *Suite) TestGetDomainSomething() { | ||
// authKeys = new(AuthKeys) | ||
// authKeys.Init() | ||
|
||
c, err := redisPool.Get() | ||
errHndlr(err) | ||
defer redisPool.Put(c) | ||
err = c.Cmd("HSET", "$domainkeys", "xyz1234567890", "peterbe.com").Err | ||
errHndlr(err) | ||
|
||
domain, err := GetDomain("xyz1234567890", c) | ||
errHndlr(err) | ||
assert.Equal( | ||
suite.T(), | ||
domain, | ||
"peterbe.com", | ||
) | ||
} | ||
|
||
func (suite *Suite) TestGetDomainNothing() { | ||
// authKeys = new(AuthKeys) | ||
// authKeys.Init() | ||
|
||
c, err := redisPool.Get() | ||
errHndlr(err) | ||
|
||
domain, err := GetDomain("xyz1234567890", c) | ||
errHndlr(err) | ||
assert.Equal( | ||
suite.T(), | ||
domain, | ||
"", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters