Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Added minor fixes for checking cachestore engine
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Apr 3, 2022

Unverified

This user has not yet uploaded their public signing key.
1 parent 8ce44c8 commit 8470760
Showing 5 changed files with 78 additions and 60 deletions.
2 changes: 1 addition & 1 deletion model_save.go
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ func saveToCache(ctx context.Context, key string, model ModelInterface, ttl time
// NOTE: this check is in place in-case a model does not load it's Parent Client
if model.Client() != nil {
c := model.Client().Cachestore()
if c != nil {
if c != nil && !c.Engine().IsEmpty() {
return c.SetModel(ctx, key, model, ttl)
}
}
6 changes: 5 additions & 1 deletion tester/database.go
Original file line number Diff line number Diff line change
@@ -56,7 +56,11 @@ func CreatePostgresServer(port uint32) (*embeddedPostgres.EmbeddedPostgres, erro
// CreateMongoServer will create a new mongo server
func CreateMongoServer(version string) (*memongo.Server, error) {
mongoServer, err := memongo.StartWithOptions(
&memongo.Options{MongoVersion: version, ShouldUseReplica: true, DownloadURL: os.Getenv("BUX_MONGODB_DOWNLOAD_URL")},
&memongo.Options{
MongoVersion: version,
ShouldUseReplica: false,
DownloadURL: os.Getenv("BUX_MONGODB_DOWNLOAD_URL"),
},
)
if err != nil {
return nil, err
57 changes: 0 additions & 57 deletions tester/database_test.go
Original file line number Diff line number Diff line change
@@ -19,63 +19,6 @@ func TestAnyGUID_Match(t *testing.T) {
// finish test
}

/*
// TestCreatePostgresServer will test the method CreatePostgresServer()
func TestCreatePostgresServer(t *testing.T) {
// t.Parallel() (disabled for now)
t.Run("valid server", func(t *testing.T) {
server, err := CreatePostgresServer(
testDatabasePort1,
)
require.NoError(t, err)
require.NotNil(t, server)
err = server.Stop()
require.NoError(t, err)
})
}*/

// TestCreateMongoServer will test the method CreateMongoServer()
func TestCreateMongoServer(t *testing.T) {
t.Parallel()

t.Run("valid server", func(t *testing.T) {
server, err := CreateMongoServer(
testMongoVersion,
)
require.NoError(t, err)
require.NotNil(t, server)
server.Stop()
})
}

// TestCreateMySQL will test the method CreateMySQL()
func TestCreateMySQL(t *testing.T) {
t.Parallel()

t.Run("valid server", func(t *testing.T) {
server, err := CreateMySQL(
testDatabaseHost, testDatabaseName, testDatabaseUser,
testDatabasePassword, testDatabasePort2,
)
require.NoError(t, err)
require.NotNil(t, server)
err = server.Close()
require.NoError(t, err)
})
}

// TestCreateMySQLTestDatabase will test the method CreateMySQLTestDatabase()
func TestCreateMySQLTestDatabase(t *testing.T) {
t.Parallel()

t.Run("valid db", func(t *testing.T) {
db := CreateMySQLTestDatabase(testDatabaseName)
require.NotNil(t, db)
assert.Equal(t, testDatabaseName, db.Name())
})
}

// TestSQLiteTestConfig will test the method SQLiteTestConfig()
func TestSQLiteTestConfig(t *testing.T) {
t.Parallel()
71 changes: 71 additions & 0 deletions tester/embedded_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build database_tests
// +build database_tests

package tester

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestCreateMongoServer will test the method CreateMongoServer()
func TestCreateMongoServer(t *testing.T) {
t.Parallel()

t.Run("valid server", func(t *testing.T) {
server, err := CreateMongoServer(
testMongoVersion,
)
require.NoError(t, err)
require.NotNil(t, server)
server.Stop()
})
}

/*
@mrz: This has some strange issues re-running and fails inconsistently
// TestCreatePostgresServer will test the method CreatePostgresServer()
func TestCreatePostgresServer(t *testing.T) {
// t.Parallel() (disabled for now)
t.Run("valid server", func(t *testing.T) {
server, err := CreatePostgresServer(
23902,
)
require.NoError(t, err)
require.NotNil(t, server)
err = server.Stop()
require.NoError(t, err)
})
}
*/

// TestCreateMySQL will test the method CreateMySQL()
func TestCreateMySQL(t *testing.T) {
t.Parallel()

t.Run("valid server", func(t *testing.T) {
server, err := CreateMySQL(
testDatabaseHost, testDatabaseName, testDatabaseUser,
testDatabasePassword, testDatabasePort2,
)
require.NoError(t, err)
require.NotNil(t, server)
err = server.Close()
require.NoError(t, err)
})
}

// TestCreateMySQLTestDatabase will test the method CreateMySQLTestDatabase()
func TestCreateMySQLTestDatabase(t *testing.T) {
t.Parallel()

t.Run("valid db", func(t *testing.T) {
db := CreateMySQLTestDatabase(testDatabaseName)
require.NotNil(t, db)
assert.Equal(t, testDatabaseName, db.Name())
})
}
2 changes: 1 addition & 1 deletion tester/tester_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
)

const (
// testDatabasePort1 = 23902
testDatabasePort1 = 23902
testDatabaseHost = "localhost"
testDatabaseName = "test"
testDatabasePassword = "tester-pw"

0 comments on commit 8470760

Please sign in to comment.