-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* expose docker manager and fix testing suite name * add apply up integration test * add test driver * implement more of apply integration test * finish apply integration test * add automatic config file creation on tests * remove unnecessary mysql connection * remove error assessment * fix mock config file creation error * separate integration tests * attempt to add coverage reports to github actions * Update Makefile Co-authored-by: Alexandre Maranhão <[email protected]> * change codecov reports Co-authored-by: Alexandre Maranhão <[email protected]>
- Loading branch information
1 parent
467e8a7
commit c2255e9
Showing
11 changed files
with
514 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ bin/ | |
.idea | ||
.vscode | ||
coverage.txt | ||
integration_coverage.txt | ||
|
||
dist | ||
.release-env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/migratemgr8/mgr8/global" | ||
"github.com/migratemgr8/mgr8/infrastructure" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Apply integration test", func() { | ||
var ( | ||
subject CommandExecutor = &apply{} | ||
) | ||
|
||
executeApply := func(args []string) { | ||
err := subject.execute( | ||
args, | ||
dm.GetConnectionString(global.Postgres), | ||
testMigrationsFolder, | ||
postgresDriver, | ||
infrastructure.CriticalLogLevel, | ||
) | ||
Expect(err).To(BeNil()) | ||
} | ||
|
||
Context("execute", func() { | ||
When("up with 3", func() { | ||
It("executes all three files that increase migration in folder", func() { | ||
AssertStateBeforeAllMigrations() | ||
executeApply([]string{"up", "3"}) | ||
AssertStateAfterAllMigrations() | ||
}) | ||
}) | ||
When("down with no number specified", func() { | ||
It("decreases one", func() { | ||
executeApply([]string{"down"}) | ||
AssertStateAfterMigration0002AndBefore0003() | ||
executeApply([]string{"down"}) | ||
AssertStateAfterMigration0001AndBefore0002() | ||
executeApply([]string{"down"}) | ||
AssertStateBeforeAllMigrations() | ||
}) | ||
}) | ||
When("different commands are executed sequentially", func() { | ||
It("should work as expected", func() { | ||
executeApply([]string{"up", "2"}) | ||
AssertStateAfterMigration0002AndBefore0003() | ||
executeApply([]string{"down", "1"}) | ||
AssertStateAfterMigration0001AndBefore0002() | ||
executeApply([]string{"up"}) | ||
AssertStateAfterMigration0002AndBefore0003() | ||
executeApply([]string{"down", "2"}) | ||
AssertStateBeforeAllMigrations() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
func AssertStateBeforeAllMigrations() { | ||
exists, err := postgresTestDriver.AssertTableExistence(userFixture0001.TableName) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
exists, err = postgresTestDriver.AssertViewExistence(userViewFixture0002.ViewName) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
} | ||
|
||
func AssertStateAfterMigration0001AndBefore0002() { | ||
exists, err := postgresTestDriver.AssertFixtureExistence(userFixture0001) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, firstNewColumnFixture0002) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
exists, err = postgresTestDriver.AssertViewExistence(userViewFixture0002.ViewName) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, secondNewColumnFixture0003) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
} | ||
|
||
func AssertStateAfterMigration0002AndBefore0003() { | ||
exists, err := postgresTestDriver.AssertFixtureExistence(userFixture0001) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, firstNewColumnFixture0002) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertViewFixtureExistence(userViewFixture0002) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, secondNewColumnFixture0003) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeFalse()) | ||
} | ||
|
||
func AssertStateAfterAllMigrations() { | ||
exists, err := postgresTestDriver.AssertFixtureExistence(userFixture0001) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, firstNewColumnFixture0002) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertViewFixtureExistence(userViewFixture0002) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
exists, err = postgresTestDriver.AssertVarcharExistence(userFixture0001.TableName, secondNewColumnFixture0003) | ||
Expect(err).To(BeNil()) | ||
Expect(exists).To(BeTrue()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/migratemgr8/mgr8/applications" | ||
"github.com/migratemgr8/mgr8/infrastructure" | ||
"github.com/migratemgr8/mgr8/testing/fixtures" | ||
"os" | ||
"testing" | ||
|
||
"github.com/migratemgr8/mgr8/domain" | ||
"github.com/migratemgr8/mgr8/drivers" | ||
"github.com/migratemgr8/mgr8/global" | ||
mgr8testing "github.com/migratemgr8/mgr8/testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _t *testing.T | ||
var dm *mgr8testing.DockerManager | ||
|
||
var ( | ||
postgresTestDriver mgr8testing.TestDriver | ||
postgresDriver domain.Driver | ||
postgresMigrations fixtures.MigrationsFixture | ||
userFixture0001 fixtures.Fixture | ||
firstNewColumnFixture0002 fixtures.VarcharFixture | ||
userViewFixture0002 fixtures.ViewFixture | ||
secondNewColumnFixture0003 fixtures.VarcharFixture | ||
) | ||
|
||
var ( | ||
testMigrationsFolder = "apply-test-migrations" | ||
mockUser = "mock-user" | ||
) | ||
|
||
func TestCommandIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping integration tests") | ||
} | ||
_t = t | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Command Test Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
createConfigFileIfNotExists() | ||
dm = mgr8testing.NewDockerManager() | ||
|
||
postgresTestDriver = mgr8testing.NewTestDriver(global.Postgres) | ||
postgresDriver = getDriverSuccessfully(global.Postgres) | ||
postgresMigrations = fixtures.NewMigrationsFixture(testMigrationsFolder, | ||
infrastructure.NewFileService(), | ||
postgresDriver.Deparser(), | ||
) | ||
userFixture0001 = postgresMigrations.AddMigration0001() | ||
firstNewColumnFixture0002, userViewFixture0002 = postgresMigrations.AddMigration0002() | ||
secondNewColumnFixture0003 = postgresMigrations.AddMigration0003() | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
err := dm.CloseAll() | ||
Expect(err).To(BeNil()) | ||
postgresMigrations.TearDown() | ||
}) | ||
|
||
func createConfigFileIfNotExists() { | ||
configPath, err := applications.GetConfigFilePath() | ||
Expect(err).To(BeNil()) | ||
config, err := os.Open(configPath) | ||
if err == nil { | ||
return | ||
} | ||
config, err = os.Create(configPath) | ||
Expect(err).To(BeNil()) | ||
username := mockUser | ||
hostname, err := os.Hostname() | ||
Expect(err).To(BeNil()) | ||
err = applications.InsertUserDetails(username, hostname, config) | ||
Expect(err).To(BeNil()) | ||
err = config.Close() | ||
Expect(err).To(BeNil()) | ||
} | ||
|
||
func getDriverSuccessfully(d global.Database) domain.Driver { | ||
driver, err := drivers.GetDriver(d) | ||
Expect(err).To(BeNil()) | ||
return driver | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fixtures | ||
|
||
import "github.com/migratemgr8/mgr8/domain" | ||
|
||
type VarcharFixture struct { | ||
Name string | ||
Cap int64 | ||
} | ||
|
||
func (f *VarcharFixture) ToDomainColumn() *domain.Column { | ||
return &domain.Column{ | ||
Parameters: map[string]interface{}{ | ||
"size": f.Cap, | ||
}, | ||
Datatype: "varchar", | ||
} | ||
} | ||
|
||
type Fixture struct { | ||
TableName string | ||
VarcharColumns []VarcharFixture | ||
TextColumns []string | ||
} | ||
|
||
func (f *Fixture) ToDomainTable() *domain.Table { | ||
t := domain.NewTable(f.TableName, map[string]*domain.Column{}) | ||
for _, varchar := range f.VarcharColumns { | ||
t.Columns[varchar.Name] = varchar.ToDomainColumn() | ||
} | ||
for _, text := range f.TextColumns { | ||
t.Columns[text] = &domain.Column{Datatype: "text"} | ||
} | ||
return t | ||
} | ||
|
||
type ViewFixture struct { | ||
ViewName string | ||
TextColumns []string | ||
VarcharColumns []VarcharFixture | ||
Statement string | ||
} |
Oops, something went wrong.