Skip to content

Commit

Permalink
Disable integration tests if SODA_DIALECT == "" (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m authored Jun 3, 2019
1 parent 2c862d3 commit 4f75084
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 46 deletions.
16 changes: 10 additions & 6 deletions associations/associations_for_struct.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package associations

import (
"errors"
"fmt"
"reflect"
"regexp"
Expand Down Expand Up @@ -40,14 +41,16 @@ func AssociationsForStruct(s interface{}, fields ...string) (Associations, error
// it throws an error when it finds a field that does
// not exist for a model.
func ForStruct(s interface{}, fields ...string) (Associations, error) {
associations := Associations{}
innerAssociations := InnerAssociations{}

t, v := getModelDefinition(s)
if t.Kind() != reflect.Struct {
return nil, errors.New("could not get struct associations: not a struct")
}
fields = trimFields(fields)
associations := Associations{}
innerAssociations := InnerAssociations{}

// validate if fields contains a non existing field in struct.
// and vefiry is it has inner associations.
// and verify is it has inner associations.
for i := range fields {
var innerField, field string

Expand All @@ -56,8 +59,9 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {
}

if strings.Contains(fields[i], ".") {
field = fields[i][:strings.Index(fields[i], ".")]
innerField = fields[i][strings.Index(fields[i], ".")+1:]
dotIndex := strings.Index(fields[i], ".")
field = fields[i][:dotIndex]
innerField = fields[i][dotIndex+1:]
fields[i] = field
}
if _, ok := t.FieldByName(fields[i]); !ok {
Expand Down
9 changes: 9 additions & 0 deletions belongs_to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func Test_BelongsTo(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)

q := PDB.BelongsTo(&User{ID: 1})
Expand All @@ -18,6 +21,9 @@ func Test_BelongsTo(t *testing.T) {
}

func Test_BelongsToAs(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)

q := PDB.BelongsToAs(&User{ID: 1}, "u_id")
Expand All @@ -29,6 +35,9 @@ func Test_BelongsToAs(t *testing.T) {
}

func Test_BelongsToThrough(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)

q := PDB.BelongsToThrough(&User{ID: 1}, &Friend{})
Expand Down
6 changes: 6 additions & 0 deletions callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func Test_Callbacks(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
r := require.New(t)

Expand Down Expand Up @@ -51,6 +54,9 @@ func Test_Callbacks(t *testing.T) {
}

func Test_Callbacks_on_Slice(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
r := require.New(t)
for i := 0; i < 2; i++ {
Expand Down
8 changes: 6 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
func Test_LoadsConnectionsFromConfig(t *testing.T) {
r := require.New(t)

conns := Connections
r.Equal(5, len(conns))
r.NoError(LoadConfigFile())
if DialectSupported("sqlite3") {
r.Equal(5, len(Connections))
} else {
r.Equal(4, len(Connections))
}
}

func Test_AddLookupPaths(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build sqlite

package pop

import (
Expand Down
1 change: 0 additions & 1 deletion dialect_sqlite_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
const nameSQLite3 = "sqlite3"

func init() {
AvailableDialects = append(AvailableDialects, nameSQLite3)
dialectSynonyms["sqlite"] = nameSQLite3
newConnection[nameSQLite3] = newSQLite
}
Expand Down
2 changes: 2 additions & 0 deletions dialect_sqlite_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build sqlite

package pop

import (
Expand Down
11 changes: 6 additions & 5 deletions executors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gobuffalo/pop/logging"
"github.com/gobuffalo/validate"
"github.com/gofrs/uuid"
"github.com/pkg/errors"
)

// Reload fetch fresh data for a given model, using its ID.
Expand Down Expand Up @@ -101,13 +102,13 @@ func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...stri
}

if c.eager {
asos, err2 := associations.ForStruct(model, c.eagerFields...)

if err2 != nil {
return verrs, err2
asos, err := associations.ForStruct(model, c.eagerFields...)
if err != nil {
return verrs, errors.Wrap(err, "could not retrieve associations")
}

if len(asos) == 0 {
log(logging.Debug, "no associations found for given struct, disable eager mode")
c.disableEager()
return verrs, c.Create(model, excludeColumns...)
}
Expand Down Expand Up @@ -169,7 +170,7 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error {
var localIsEager = isEager
asos, err := associations.ForStruct(m.Value, c.eagerFields...)
if err != nil {
return err
return errors.Wrap(err, "could not retrieve associations")
}

if localIsEager && len(asos) == 0 {
Expand Down
Loading

0 comments on commit 4f75084

Please sign in to comment.