Skip to content

Commit

Permalink
using true random strings
Browse files Browse the repository at this point in the history
  • Loading branch information
erickpintor committed Oct 25, 2016
1 parent 892ae90 commit 8896fd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
9 changes: 1 addition & 8 deletions faunadb/client_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package faunadb_test

import (
"fmt"
"math/rand"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -437,7 +434,7 @@ func (s *ClientTestSuite) TestEvalIfExpression() {
func (s *ClientTestSuite) TestEvalDoExpression() {
var ref f.RefV

refToCreate := f.Ref(s.randomStartingWith(randomClass.ID, "/"))
refToCreate := f.Ref(f.RandomStartingWith(randomClass.ID, "/"))

res := s.queryForRef(
f.Do(
Expand Down Expand Up @@ -997,7 +994,3 @@ func (s *ClientTestSuite) queryAndDecode(expr f.Expr, i interface{}) {
value := s.query(expr)
s.Require().NoError(value.Get(i))
}

func (s *ClientTestSuite) randomStartingWith(parts ...string) string {
return fmt.Sprintf("%s%v", strings.Join(parts, ""), rand.Uint32())
}
27 changes: 20 additions & 7 deletions faunadb/faunadb_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package faunadb

import "os"

const dbName = "faunadb-go-test"
import (
"fmt"
"math/rand"
"os"
"strings"
"time"
)

var (
defaultConfig = map[string]string{
Expand All @@ -12,15 +16,20 @@ var (
"FAUNA_PORT": "8443",
}

faunaSecret, faunaEndpoint string
faunaSecret = getConfig("FAUNA_ROOT_KEY")
faunaEndpoint = os.Expand("${FAUNA_SCHEME}://${FAUNA_DOMAIN}:${FAUNA_PORT}", getConfig)

dbName string
dbRef Expr

adminClient *FaunaClient
dbRef = Database(dbName)
)

func init() {
faunaSecret = getConfig("FAUNA_ROOT_KEY")
faunaEndpoint = os.Expand("${FAUNA_SCHEME}://${FAUNA_DOMAIN}:${FAUNA_PORT}", getConfig)
rand.Seed(time.Now().UTC().UnixNano()) // By default, the seed is always 1

dbName = RandomStartingWith("faunadb-go-test-")
dbRef = Database(dbName)
}

func getConfig(key string) (value string) {
Expand All @@ -31,6 +40,10 @@ func getConfig(key string) (value string) {
return
}

func RandomStartingWith(parts ...string) string {
return fmt.Sprintf("%s%v", strings.Join(parts, ""), rand.Uint32())
}

func SetupTestDB() (client *FaunaClient, err error) {
var key string

Expand Down

0 comments on commit 8896fd5

Please sign in to comment.