Permalink
Browse files

Add integration test suite for extensive coverage

This suite tests against a Dockerized DB instance of one or more versions/
flavors of MySQL, and includes functional testing of all Skeema commands.
  • Loading branch information...
evanelias committed May 25, 2018
1 parent a670408 commit 886496e8bc89ab6852278be7d2fc8325d38f4474
Showing with 1,772 additions and 0 deletions.
  1. +26 −0 .travis.yml
  2. +96 −0 ddlstatement_test.go
  3. +34 −0 exit_test.go
  4. +622 −0 skeema_cmd_test.go
  5. +408 −0 skeema_test.go
  6. +133 −0 sqlfile_test.go
  7. +11 −0 testdata/ddlstatement.sql
  8. +3 −0 testdata/golden/autoinc/mydb/.skeema
  9. +1 −0 testdata/golden/autoinc/mydb/analytics/.skeema
  10. +9 −0 testdata/golden/autoinc/mydb/analytics/activity.sql
  11. +8 −0 testdata/golden/autoinc/mydb/analytics/pageviews.sql
  12. +5 −0 testdata/golden/autoinc/mydb/analytics/rollups.sql
  13. +1 −0 testdata/golden/autoinc/mydb/product/.skeema
  14. +8 −0 testdata/golden/autoinc/mydb/product/comments.sql
  15. +9 −0 testdata/golden/autoinc/mydb/product/posts.sql
  16. +7 −0 testdata/golden/autoinc/mydb/product/subscriptions.sql
  17. +8 −0 testdata/golden/autoinc/mydb/product/users.sql
  18. +5 −0 testdata/golden/ignore/mydb/.skeema
  19. +1 −0 testdata/golden/ignore/mydb/analytics/.skeema
  20. +9 −0 testdata/golden/ignore/mydb/analytics/activity.sql
  21. +8 −0 testdata/golden/ignore/mydb/analytics/pageviews.sql
  22. +5 −0 testdata/golden/ignore/mydb/analytics/rollups.sql
  23. +1 −0 testdata/golden/ignore/mydb/product/.skeema
  24. +8 −0 testdata/golden/ignore/mydb/product/comments.sql
  25. +9 −0 testdata/golden/ignore/mydb/product/posts.sql
  26. +7 −0 testdata/golden/ignore/mydb/product/subscriptions.sql
  27. +8 −0 testdata/golden/ignore/mydb/product/users.sql
  28. +3 −0 testdata/golden/init/mydb/.skeema
  29. +1 −0 testdata/golden/init/mydb/analytics/.skeema
  30. +9 −0 testdata/golden/init/mydb/analytics/activity.sql
  31. +8 −0 testdata/golden/init/mydb/analytics/pageviews.sql
  32. +5 −0 testdata/golden/init/mydb/analytics/rollups.sql
  33. +1 −0 testdata/golden/init/mydb/product/.skeema
  34. +8 −0 testdata/golden/init/mydb/product/comments.sql
  35. +9 −0 testdata/golden/init/mydb/product/posts.sql
  36. +7 −0 testdata/golden/init/mydb/product/subscriptions.sql
  37. +8 −0 testdata/golden/init/mydb/product/users.sql
  38. +3 −0 testdata/golden/pull1/mydb/.skeema
  39. +3 −0 testdata/golden/pull1/mydb/analytics/.skeema
  40. +9 −0 testdata/golden/pull1/mydb/analytics/activity.sql
  41. +8 −0 testdata/golden/pull1/mydb/analytics/pageviews.sql
  42. +5 −0 testdata/golden/pull1/mydb/analytics/rollups.sql
  43. +5 −0 testdata/golden/pull1/mydb/analytics/widget_counts.sql
  44. +3 −0 testdata/golden/pull1/mydb/archives/.skeema
  45. +4 −0 testdata/golden/pull1/mydb/archives/foo.sql
  46. +1 −0 testdata/golden/pull1/mydb/product/.skeema
  47. +10 −0 testdata/golden/pull1/mydb/product/posts.sql
  48. +7 −0 testdata/golden/pull1/mydb/product/subscriptions.sql
  49. +8 −0 testdata/golden/pull1/mydb/product/users.sql
  50. +3 −0 testdata/golden/unsupported/mydb/.skeema
  51. +1 −0 testdata/golden/unsupported/mydb/analytics/.skeema
  52. +9 −0 testdata/golden/unsupported/mydb/analytics/activity.sql
  53. +8 −0 testdata/golden/unsupported/mydb/analytics/pageviews.sql
  54. +5 −0 testdata/golden/unsupported/mydb/analytics/rollups.sql
  55. +1 −0 testdata/golden/unsupported/mydb/product/.skeema
  56. +8 −0 testdata/golden/unsupported/mydb/product/comments.sql
  57. +9 −0 testdata/golden/unsupported/mydb/product/posts.sql
  58. +12 −0 testdata/golden/unsupported/mydb/product/subscriptions.sql
  59. +8 −0 testdata/golden/unsupported/mydb/product/users.sql
  60. +21 −0 testdata/ignore1.sql
  61. +18 −0 testdata/pull1.sql
  62. +17 −0 testdata/push1.sql
  63. +67 −0 testdata/setup.sql
  64. +10 −0 testdata/unsupported1.sql
View
@@ -0,0 +1,26 @@
sudo: required
language: go
go:
- "1.10.x"
services:
- docker
notifications:
email: false
env:
global:
- SKEEMA_TEST_IMAGES="mysql:5.6,mysql:5.7"
before_install:
- go get golang.org/x/lint/golint
- go get github.com/mattn/goveralls
script:
- go test -v -coverprofile=coverage.out -covermode=count
- go vet ./...
- test -z "$(gofmt -s -d *.go 2>&1)"
- golint -set_exit_status .
after_script:
- goveralls -coverprofile=coverage.out -service=travis-ci
View
@@ -0,0 +1,96 @@
package main
import (
"testing"
"github.com/skeema/mybase"
"github.com/skeema/tengo"
)
func (s *SkeemaIntegrationSuite) TestNewDDLStatement(t *testing.T) {
// Setup: init files and then change the DB so that we have some
// differences to generate. We first add a default value to domain col
// to later test that quoting rules are working properly for shellouts.
s.dbExec(t, "analytics", "ALTER TABLE pageviews MODIFY COLUMN domain varchar(40) NOT NULL DEFAULT 'skeema.net'")
s.handleCommand(t, CodeSuccess, ".", "skeema init --dir mydb -h %s -P %d", s.d.Instance.Host, s.d.Instance.Port)
s.sourceSQL(t, "ddlstatement.sql")
// Generate a diff a bit manually
fakeFileSource := mybase.SimpleSource(map[string]string{
"password": s.d.Instance.Password,
"debug": "1",
"allow-unsafe": "1",
"ddl-wrapper": "/bin/echo ddl-wrapper {SCHEMA}.{TABLE} {TYPE}",
"alter-wrapper": "/bin/echo alter-wrapper {SCHEMA}.{TABLE} {TYPE} {CLAUSES}",
"alter-wrapper-min-size": "1",
"alter-algorithm": "INPLACE",
"alter-lock": "NONE",
})
cfg := mybase.ParseFakeCLI(t, CommandSuite, "skeema diff ", fakeFileSource)
AddGlobalConfigFiles(cfg)
dir, err := NewDir(".", cfg)
if err != nil {
t.Fatalf("Unexpected error from NewDir: %s", err)
}
var target *Target
for _, thisTarget := range dir.Targets() {
if thisTarget.SchemaFromInstance.Name == "analytics" {
target = thisTarget
break
}
}
sd, err := tengo.NewSchemaDiff(target.SchemaFromInstance, target.SchemaFromDir)
if err != nil {
t.Fatalf("Unexpected error from tengo.NewSchemaDiff: %s", err)
}
if len(sd.TableDiffs) != 4 {
// modifications in ddlstatement.sql should have yielded 4 diffs: one drop
// table, one create table, and two alter tables (one to a table with rows
// and one to a table without rows)
t.Fatalf("Expected 4 table diffs, instead found %d", len(sd.TableDiffs))
}
mods := tengo.StatementModifiers{
AllowUnsafe: true,
LockClause: "NONE",
AlgorithmClause: "INPLACE",
}
for _, diff := range sd.TableDiffs {
ddl := NewDDLStatement(diff, mods, target)
if ddl.Err != nil {
t.Errorf("Unexpected DDLStatement error: %s", ddl.Err)
}
if !ddl.IsShellOut() {
t.Fatalf("Expected this configuration to result in all DDLs being shellouts, but %v is not", ddl)
}
var expected string
switch diff := diff.(type) {
case tengo.AlterTable:
if diff.Table.Name == "rollups" {
// no rows, so ddl-wrapper used. verify the statement separately.
expected = "/bin/echo ddl-wrapper analytics.rollups ALTER"
expectedStmt := "ALTER TABLE `rollups` ALGORITHM=INPLACE, LOCK=NONE, ADD COLUMN `value` bigint(20) DEFAULT NULL"
if ddl.stmt != expectedStmt {
t.Errorf("Expected statement:\n%s\nActual statement:\n%s\n", expectedStmt, ddl.stmt)
}
} else if diff.Table.Name == "pageviews" {
// has 1 row, so alter-wrapper used. verify the execution separately to
// sanity-check the quoting rules.
expected = "/bin/echo alter-wrapper analytics.pageviews ALTER 'ADD COLUMN `domain` varchar(40) NOT NULL DEFAULT '\"'\"'skeema.net'\"'\"''"
expectedOutput := "alter-wrapper analytics.pageviews ALTER ADD COLUMN `domain` varchar(40) NOT NULL DEFAULT 'skeema.net'\n"
if actualOutput, err := ddl.shellOut.RunCapture(); err != nil || actualOutput != expectedOutput {
t.Errorf("Expected output:\n%sActual output:\n%sErr:\n%v\n", expectedOutput, actualOutput, err)
}
} else {
t.Fatalf("Unexpected AlterTable for %s; perhaps test fixture changed without updating this test?", diff.Table.Name)
}
case tengo.DropTable:
expected = "/bin/echo ddl-wrapper analytics.widget_counts DROP"
case tengo.CreateTable:
expected = "/bin/echo ddl-wrapper analytics.activity CREATE"
}
if ddl.shellOut.Command != expected {
t.Errorf("Expected shellout:\n%s\nActual shellout:\n%s\n", expected, ddl.shellOut.Command)
}
}
}
View
@@ -0,0 +1,34 @@
package main
import (
"errors"
"testing"
)
func TestExitCode(t *testing.T) {
err := errors.New("test error")
if ExitCode(err) != CodeFatalError {
t.Errorf("Expected exit code for non-nil non-ExitValue to be %d, instead found %d", CodeFatalError, ExitCode(err))
}
err = nil
if ExitCode(err) != CodeSuccess {
t.Errorf("Expected exit code for nil error to be %d, instead found %d", CodeSuccess, ExitCode(err))
}
err = NewExitValue(CodePartialError, "test error")
if ExitCode(err) != CodePartialError {
t.Errorf("Expected exit code to be %d, instead found %d", CodePartialError, ExitCode(err))
}
}
func TestExitValueError(t *testing.T) {
err := NewExitValue(CodeBadConfig, "test format string %s %t", "hello world", true)
expected := "test format string hello world true"
if actual := err.Error(); actual != expected {
t.Errorf("Found message %v, expected %v", actual, expected)
}
err = nil
expected = ""
if actual := err.Error(); actual != expected {
t.Errorf("Found message %v, expected %v", actual, expected)
}
}
Oops, something went wrong.

0 comments on commit 886496e

Please sign in to comment.