(Feat): Initial Commit
This commit is contained in:
36
internal/data/fixtures/fixtures.go
Normal file
36
internal/data/fixtures/fixtures.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"allaboutapps.dev/aw/go-starter/internal/models"
|
||||
"allaboutapps.dev/aw/go-starter/internal/util"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
)
|
||||
|
||||
// Live Service fixtures to be applied by manually running the CLI "app db seed"
|
||||
// Note that these fixtures are not available while testing
|
||||
// see the separate internal/test/fixtures.go file
|
||||
|
||||
type Upsertable interface {
|
||||
Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...models.UpsertOptionFunc) error
|
||||
}
|
||||
|
||||
// Mind the declaration order! The fields get upserted exactly in the order they are declared.
|
||||
type FixtureMap struct{}
|
||||
|
||||
func Fixtures() FixtureMap {
|
||||
return FixtureMap{}
|
||||
}
|
||||
|
||||
func Upserts() []Upsertable {
|
||||
fix := Fixtures()
|
||||
upsertableIfc := (*Upsertable)(nil)
|
||||
upserts, err := util.GetFieldsImplementing(&fix, upsertableIfc)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to get upsertable fixture fields: %w", err))
|
||||
}
|
||||
|
||||
return upserts
|
||||
}
|
||||
18
internal/data/fixtures/fixtures_test.go
Normal file
18
internal/data/fixtures/fixtures_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package fixtures_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
data "allaboutapps.dev/aw/go-starter/internal/data/fixtures"
|
||||
"allaboutapps.dev/aw/go-starter/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUpsertableInterface(t *testing.T) {
|
||||
var user any = &models.AppUserProfile{
|
||||
UserID: "62b13d29-5c4e-420e-b991-a631d3938776",
|
||||
}
|
||||
|
||||
_, ok := user.(data.Upsertable)
|
||||
assert.True(t, ok, "AppUserProfile should implement the Upsertable interface")
|
||||
}
|
||||
Reference in New Issue
Block a user