Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run go tests in a package-specific database #1776

Draft
wants to merge 20 commits into
base: master
from
Draft
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+141 −83
Diff settings

Always

Just for now

1 .envrc
@@ -57,6 +57,7 @@ export MYMOVE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export SECURE_MIGRATION_DIR="${MYMOVE_DIR}/local_migrations"
export SECURE_MIGRATION_SOURCE="local"
export DB_PASSWORD=mysecretpassword
export PGPASSWORD=$DB_PASSWORD

This comment has been minimized.

Copy link
@chrisgilmerproj

chrisgilmerproj Feb 22, 2019

Contributor

Setting this explicitly should only cause a problem if we have multiple DB instances with different passwords, right?

export DB_USER=postgres
export DB_HOST=localhost
export DB_PORT=5432
@@ -214,9 +214,8 @@ endif

server_test: server_deps server_generate db_test_reset db_test_migrate
# Don't run tests in /cmd or /pkg/gen & pass `-short` to exclude long running tests
# Use -test.parallel 1 to test packages serially and avoid database collisions
# Disable test caching with `-count 1` - caching was masking local test failures
go test -p 1 -count 1 -short $$(go list ./... | grep -v \\/pkg\\/gen\\/ | grep -v \\/cmd\\/)
go test -count 1 -short $$(go list ./... | grep -v \\/pkg\\/gen\\/ | grep -v \\/cmd\\/)

server_test_all: server_deps server_generate db_dev_reset db_dev_migrate
# Like server_test but runs extended tests that may hit external services.
@@ -1,6 +1,7 @@
package dutystationsloader

import (
"github.com/transcom/mymove/pkg/testingsuite"
"log"
"reflect"
"testing"
@@ -16,44 +17,23 @@ import (
)

type DutyStationsLoaderSuite struct {
suite.Suite
db *pop.Connection
testingsuite.PopTestSuite
logger *zap.Logger
}

func (suite *DutyStationsLoaderSuite) SetupTest() {
suite.db.TruncateAll()
}

func (suite *DutyStationsLoaderSuite) mustSave(model interface{}) {
t := suite.T()
t.Helper()

verrs, err := suite.db.ValidateAndSave(model)
if err != nil {
suite.T().Errorf("Errors encountered saving %v: %v", model, err)
}
if verrs.HasAny() {
suite.T().Errorf("Validation errors encountered saving %v: %v", model, verrs)
}
suite.DB().TruncateAll()
}

func TestDutyStationsLoaderSuite(t *testing.T) {
configLocation := "../../../config"
pop.AddLookupPaths(configLocation)
db, err := pop.Connect("test")
if err != nil {
log.Panic(err)
}

logger, err := zap.NewDevelopment()
if err != nil {
log.Panic(err)
}

hs := &DutyStationsLoaderSuite{
db: db,
logger: logger,
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}

suite.Run(t, hs)
@@ -63,7 +43,7 @@ func (suite *DutyStationsLoaderSuite) TestParsingFunctions() {
stationsPath := "./testdata/stations.xlsx"
officesPath := "./testdata/offices.xlsx"

builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)

stationRows, err := builder.parseStations(stationsPath)
suite.NoError(err)
@@ -81,7 +61,7 @@ func (suite *DutyStationsLoaderSuite) TestParsingFunctions() {
}

func (suite *DutyStationsLoaderSuite) TestInsertionString() {
builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)

something := "something"
zeroID := uuid.Nil
@@ -99,7 +79,7 @@ func (suite *DutyStationsLoaderSuite) TestInsertionString() {
}

func (suite *DutyStationsLoaderSuite) TestCreateInsertQuery() {
builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)

model := models.User{
ID: uuid.Must(uuid.FromString("cd40c92e-7c8a-4da4-ad58-4480df84b3f0")),
@@ -122,7 +102,7 @@ func (suite *DutyStationsLoaderSuite) TestSeparateStations() {
State: "CA",
PostalCode: postalCode1,
}
suite.mustSave(&address1)
suite.MustSave(&address1)

savedName := "Saved!"
saved := models.DutyStation{
@@ -131,7 +111,7 @@ func (suite *DutyStationsLoaderSuite) TestSeparateStations() {
Name: savedName,
Affiliation: internalmessages.AffiliationARMY,
}
suite.mustSave(&saved)
suite.MustSave(&saved)

postalCode2 := "00002"
address2 := models.Address{
@@ -149,7 +129,7 @@ func (suite *DutyStationsLoaderSuite) TestSeparateStations() {
Affiliation: internalmessages.AffiliationARMY,
}

builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)
new, existing, err := builder.separateExistingStations([]DutyStationWrapper{
DutyStationWrapper{
TransportationOfficeName: "Some name",
@@ -178,15 +158,15 @@ func (suite *DutyStationsLoaderSuite) TestCheckForDuplicates() {
State: "CA",
PostalCode: postalCode,
}
suite.mustSave(&address)
suite.MustSave(&address)

savedName := "Some Office"
saved := models.TransportationOffice{
AddressID: address.ID,
Address: address,
Name: savedName,
}
suite.mustSave(&saved)
suite.MustSave(&saved)

postalCode2 := "00002"
address2 := models.Address{
@@ -203,7 +183,7 @@ func (suite *DutyStationsLoaderSuite) TestCheckForDuplicates() {
Name: notSavedName,
}

builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)
new, existing, err := builder.separateExistingOffices([]models.TransportationOffice{saved, notSaved})

suite.NoError(err)
@@ -256,7 +236,7 @@ func (suite *DutyStationsLoaderSuite) TestPairStationsOffices() {
},
}

builder := NewMigrationBuilder(suite.db, suite.logger)
builder := NewMigrationBuilder(suite.DB(), suite.logger)
pairs := builder.pairOfficesToStations(
[]DutyStationWrapper{station1, station2, station3},
[]TransportationOfficeWrapper{office1, office2})
@@ -34,7 +34,7 @@ func TestAuthSuite(t *testing.T) {
log.Panic(err)
}
hs := &AuthSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, hs)
@@ -792,7 +792,7 @@ func TestAwardQueueSuite(t *testing.T) {
}

hs := &AwardQueueSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: &hnyzap.Logger{Logger: logger},
}
suite.Run(t, hs)
@@ -140,7 +140,7 @@ func TestDatesSuite(t *testing.T) {
}

hs := &DatesSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: &hnyzap.Logger{Logger: logger},
}
suite.Run(t, hs)
@@ -21,7 +21,7 @@ func (suite *DBFmtSuite) SetupTest() {

func TestDBFmtSuite(t *testing.T) {
hs := &DBFmtSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
}
suite.Run(t, hs)
}
@@ -27,7 +27,7 @@ func TestSequenceSuite(t *testing.T) {
logger := zap.NewNop()

hs := &SequenceSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, hs)
@@ -315,7 +315,7 @@ func TestInvoiceSuite(t *testing.T) {
v.AutomaticEnv()

hs := &InvoiceSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
Viper: v,
}
@@ -27,9 +27,9 @@ type BaseHandlerTestSuite struct {
}

// NewBaseHandlerTestSuite returns a new BaseHandlerTestSuite
func NewBaseHandlerTestSuite(logger *zap.Logger, sender notifications.NotificationSender) BaseHandlerTestSuite {
func NewBaseHandlerTestSuite(logger *zap.Logger, sender notifications.NotificationSender, packageName testingsuite.PackageName) BaseHandlerTestSuite {
return BaseHandlerTestSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(packageName),
logger: logger,
notificationSender: sender,
}
@@ -1,6 +1,7 @@
package dpsapi

import (
"github.com/transcom/mymove/pkg/testingsuite"
"log"
"testing"

@@ -23,7 +24,7 @@ func TestHandlerSuite(t *testing.T) {
}

hs := &HandlerSuite{
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger)),
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger), testingsuite.CurrentPackage()),
}

suite.Run(t, hs)
@@ -1,6 +1,7 @@
package internalapi

import (
"github.com/transcom/mymove/pkg/testingsuite"
"log"
"testing"

@@ -36,7 +37,7 @@ func TestHandlerSuite(t *testing.T) {
}

hs := &HandlerSuite{
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger)),
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger), testingsuite.CurrentPackage()),
}

suite.Run(t, hs)
@@ -1,6 +1,7 @@
package publicapi

import (
"github.com/transcom/mymove/pkg/testingsuite"
"log"
"testing"

@@ -36,7 +37,7 @@ func TestHandlerSuite(t *testing.T) {
}

hs := &HandlerSuite{
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger)),
BaseHandlerTestSuite: handlers.NewBaseHandlerTestSuite(logger, notifications.NewStubNotificationSender("milmovelocal", logger), testingsuite.CurrentPackage()),
}

suite.Run(t, hs)
@@ -62,7 +62,7 @@ func (suite *ModelSuite) noValidationErrors(verrs *validate.Errors, err error) b
}

func TestModelSuite(t *testing.T) {
hs := &ModelSuite{PopTestSuite: testingsuite.NewPopTestSuite()}
hs := &ModelSuite{PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage())}
suite.Run(t, hs)
}

@@ -99,7 +99,7 @@ func TestNotificationSuite(t *testing.T) {
logger, _ := zap.NewDevelopment()

s := &NotificationSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, s)
@@ -65,7 +65,7 @@ func TestPaperworkSuite(t *testing.T) {
}
storer := storageTest.NewFakeS3Storage(true)

popSuite := testingsuite.NewPopTestSuite()
popSuite := testingsuite.NewPopTestSuite(testingsuite.CurrentPackage())
hs := &PaperworkSuite{
PopTestSuite: popSuite,
logger: logger,
@@ -205,7 +205,7 @@ func TestRateEngineSuite(t *testing.T) {
planner := route.NewTestingPlanner(1234)

hs := &RateEngineSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
planner: planner,
}
@@ -33,7 +33,7 @@ func TestInvoiceSuite(t *testing.T) {
fakeS3 := storageTest.NewFakeS3Storage(true)

hs := &InvoiceServiceSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
storer: fakeS3,
}
@@ -1,38 +1,33 @@
package invoice

import (
"log"
"github.com/transcom/mymove/pkg/testingsuite"
"net/http"
"net/http/httptest"
"testing"

"github.com/gobuffalo/pop"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
)

type GexSuite struct {
suite.Suite
db *pop.Connection
testingsuite.PopTestSuite
logger *zap.Logger
}

func (suite *GexSuite) SetupTest() {
suite.db.TruncateAll()
suite.DB().TruncateAll()
}

func TestGexSuite(t *testing.T) {
configLocation := "../../../config"
pop.AddLookupPaths(configLocation)
db, err := pop.Connect("test")
if err != nil {
log.Panic(err)
}

// Use a no-op logger during testing
logger := zap.NewNop()

hs := &GexSuite{db: db, logger: logger}
hs := &GexSuite{
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, hs)
}

@@ -31,7 +31,7 @@ func TestCreateFormSuite(t *testing.T) {
logger := zap.NewNop()

hs := &CreateFormSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, hs)
@@ -72,7 +72,7 @@ func TestUpdateInvoiceSuite(t *testing.T) {
logger := zap.NewNop()

hs := &DeliverPriceShipmentSuite{
PopTestSuite: testingsuite.NewPopTestSuite(),
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage()),
logger: logger,
}
suite.Run(t, hs)
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.