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

feat: bump onpar #444

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 57 additions & 50 deletions dialect_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !integration
// +build !integration

package gorp_test
Expand All @@ -21,15 +22,21 @@ import (
)

func TestMySQLDialect(t *testing.T) {
o := onpar.New()
defer o.Run(t)
type testContext struct {
expect expect.Expectation
dialect gorp.MySQLDialect
}

o.BeforeEach(func(t *testing.T) (expect.Expectation, gorp.MySQLDialect) {
return expect.New(t), gorp.MySQLDialect{
Engine: "foo",
Encoding: "bar",
o := onpar.BeforeEach(onpar.New(t), func(t *testing.T) testContext {
return testContext{
expect: expect.New(t),
dialect: gorp.MySQLDialect{
Engine: "foo",
Encoding: "bar",
},
}
})
defer o.Run()

o.Group("ToSqlType", func() {
tests := []struct {
Expand Down Expand Up @@ -62,97 +69,97 @@ func TestMySQLDialect(t *testing.T) {
{"large string", "", 1024, false, "text"},
}
for _, t := range tests {
o.Spec(t.name, func(expect expect.Expectation, dialect gorp.MySQLDialect) {
o.Spec(t.name, func(tt testContext) {
typ := reflect.TypeOf(t.value)
sqlType := dialect.ToSqlType(typ, t.maxSize, t.autoIncr)
expect(sqlType).To(matchers.Equal(t.expected))
sqlType := tt.dialect.ToSqlType(typ, t.maxSize, t.autoIncr)
tt.expect(sqlType).To(matchers.Equal(t.expected))
})
}
})

o.Spec("AutoIncrStr", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.AutoIncrStr()).To(matchers.Equal("auto_increment"))
o.Spec("AutoIncrStr", func(tt testContext) {
tt.expect(tt.dialect.AutoIncrStr()).To(matchers.Equal("auto_increment"))
})

o.Spec("AutoIncrBindValue", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.AutoIncrBindValue()).To(matchers.Equal("null"))
o.Spec("AutoIncrBindValue", func(tt testContext) {
tt.expect(tt.dialect.AutoIncrBindValue()).To(matchers.Equal("null"))
})

o.Spec("AutoIncrInsertSuffix", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.AutoIncrInsertSuffix(nil)).To(matchers.Equal(""))
o.Spec("AutoIncrInsertSuffix", func(tt testContext) {
tt.expect(tt.dialect.AutoIncrInsertSuffix(nil)).To(matchers.Equal(""))
})

o.Group("CreateTableSuffix", func() {
o.Group("with an empty engine", func() {
o.BeforeEach(func(expect expect.Expectation, dialect gorp.MySQLDialect) (expect.Expectation, gorp.MySQLDialect) {
dialect.Engine = ""
return expect, dialect
o := onpar.BeforeEach(o, func(tt testContext) testContext {
tt.dialect.Engine = ""
return tt
})
o.Spec("panics", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(func() { dialect.CreateTableSuffix() }).To(Panic())
o.Spec("panics", func(tt testContext) {
tt.expect(func() { tt.dialect.CreateTableSuffix() }).To(Panic())
})
})

o.Group("with an empty encoding", func() {
o.BeforeEach(func(expect expect.Expectation, dialect gorp.MySQLDialect) (expect.Expectation, gorp.MySQLDialect) {
dialect.Encoding = ""
return expect, dialect
o := onpar.BeforeEach(o, func(tt testContext) testContext {
tt.dialect.Encoding = ""
return tt
})
o.Spec("panics", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(func() { dialect.CreateTableSuffix() }).To(Panic())
o.Spec("panics", func(tt testContext) {
tt.expect(func() { tt.dialect.CreateTableSuffix() }).To(Panic())
})
})

o.Spec("with an engine and an encoding", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.CreateTableSuffix()).To(matchers.Equal(" engine=foo charset=bar"))
o.Spec("with an engine and an encoding", func(tt testContext) {
tt.expect(tt.dialect.CreateTableSuffix()).To(matchers.Equal(" engine=foo charset=bar"))
})
})

o.Spec("CreateIndexSuffix", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.CreateIndexSuffix()).To(matchers.Equal("using"))
o.Spec("CreateIndexSuffix", func(tt testContext) {
tt.expect(tt.dialect.CreateIndexSuffix()).To(matchers.Equal("using"))
})

o.Spec("DropIndexSuffix", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.DropIndexSuffix()).To(matchers.Equal("on"))
o.Spec("DropIndexSuffix", func(tt testContext) {
tt.expect(tt.dialect.DropIndexSuffix()).To(matchers.Equal("on"))
})

o.Spec("TruncateClause", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.TruncateClause()).To(matchers.Equal("truncate"))
o.Spec("TruncateClause", func(tt testContext) {
tt.expect(tt.dialect.TruncateClause()).To(matchers.Equal("truncate"))
})

o.Spec("SleepClause", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.SleepClause(1 * time.Second)).To(matchers.Equal("sleep(1.000000)"))
expect(dialect.SleepClause(100 * time.Millisecond)).To(matchers.Equal("sleep(0.100000)"))
o.Spec("SleepClause", func(tt testContext) {
tt.expect(tt.dialect.SleepClause(1 * time.Second)).To(matchers.Equal("sleep(1.000000)"))
tt.expect(tt.dialect.SleepClause(100 * time.Millisecond)).To(matchers.Equal("sleep(0.100000)"))
})

o.Spec("BindVar", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.BindVar(0)).To(matchers.Equal("?"))
o.Spec("BindVar", func(tt testContext) {
tt.expect(tt.dialect.BindVar(0)).To(matchers.Equal("?"))
})

o.Spec("QuoteField", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.QuoteField("foo")).To(matchers.Equal("`foo`"))
o.Spec("QuoteField", func(tt testContext) {
tt.expect(tt.dialect.QuoteField("foo")).To(matchers.Equal("`foo`"))
})

o.Group("QuotedTableForQuery", func() {
o.Spec("using the default schema", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.QuotedTableForQuery("", "foo")).To(matchers.Equal("`foo`"))
o.Spec("using the default schema", func(tt testContext) {
tt.expect(tt.dialect.QuotedTableForQuery("", "foo")).To(matchers.Equal("`foo`"))
})

o.Spec("with a supplied schema", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.QuotedTableForQuery("foo", "bar")).To(matchers.Equal("foo.`bar`"))
o.Spec("with a supplied schema", func(tt testContext) {
tt.expect(tt.dialect.QuotedTableForQuery("foo", "bar")).To(matchers.Equal("foo.`bar`"))
})
})

o.Spec("IfSchemaNotExists", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.IfSchemaNotExists("foo", "bar")).To(matchers.Equal("foo if not exists"))
o.Spec("IfSchemaNotExists", func(tt testContext) {
tt.expect(tt.dialect.IfSchemaNotExists("foo", "bar")).To(matchers.Equal("foo if not exists"))
})

o.Spec("IfTableExists", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.IfTableExists("foo", "bar", "baz")).To(matchers.Equal("foo if exists"))
o.Spec("IfTableExists", func(tt testContext) {
tt.expect(tt.dialect.IfTableExists("foo", "bar", "baz")).To(matchers.Equal("foo if exists"))
})

o.Spec("IfTableNotExists", func(expect expect.Expectation, dialect gorp.MySQLDialect) {
expect(dialect.IfTableNotExists("foo", "bar", "baz")).To(matchers.Equal("foo if not exists"))
o.Spec("IfTableNotExists", func(tt testContext) {
tt.expect(tt.dialect.IfTableNotExists("foo", "bar", "baz")).To(matchers.Equal("foo if not exists"))
})
}

Expand Down
101 changes: 54 additions & 47 deletions dialect_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !integration
// +build !integration

package gorp_test
Expand All @@ -19,14 +20,20 @@ import (
)

func TestPostgresDialect(t *testing.T) {
o := onpar.New()
defer o.Run(t)

o.BeforeEach(func(t *testing.T) (expect.Expectation, gorp.PostgresDialect) {
return expect.New(t), gorp.PostgresDialect{
LowercaseFields: false,
type testContext struct {
expect expect.Expectation
dialect gorp.PostgresDialect
}

o := onpar.BeforeEach(onpar.New(t), func(t *testing.T) testContext {
return testContext{
expect: expect.New(t),
dialect: gorp.PostgresDialect{
LowercaseFields: false,
},
}
})
defer o.Run()

o.Group("ToSqlType", func() {
tests := []struct {
Expand Down Expand Up @@ -59,92 +66,92 @@ func TestPostgresDialect(t *testing.T) {
{"large string", "", 1024, false, "varchar(1024)"},
}
for _, t := range tests {
o.Spec(t.name, func(expect expect.Expectation, dialect gorp.PostgresDialect) {
o.Spec(t.name, func(tt testContext) {
typ := reflect.TypeOf(t.value)
sqlType := dialect.ToSqlType(typ, t.maxSize, t.autoIncr)
expect(sqlType).To(matchers.Equal(t.expected))
sqlType := tt.dialect.ToSqlType(typ, t.maxSize, t.autoIncr)
tt.expect(sqlType).To(matchers.Equal(t.expected))
})
}
})

o.Spec("AutoIncrStr", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.AutoIncrStr()).To(matchers.Equal(""))
o.Spec("AutoIncrStr", func(tt testContext) {
tt.expect(tt.dialect.AutoIncrStr()).To(matchers.Equal(""))
})

o.Spec("AutoIncrBindValue", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.AutoIncrBindValue()).To(matchers.Equal("default"))
o.Spec("AutoIncrBindValue", func(tt testContext) {
tt.expect(tt.dialect.AutoIncrBindValue()).To(matchers.Equal("default"))
})

o.Spec("AutoIncrInsertSuffix", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
o.Spec("AutoIncrInsertSuffix", func(tt testContext) {
cm := gorp.ColumnMap{
ColumnName: "foo",
}
expect(dialect.AutoIncrInsertSuffix(&cm)).To(matchers.Equal(` returning "foo"`))
tt.expect(tt.dialect.AutoIncrInsertSuffix(&cm)).To(matchers.Equal(` returning "foo"`))
})

o.Spec("CreateTableSuffix", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.CreateTableSuffix()).To(matchers.Equal(""))
o.Spec("CreateTableSuffix", func(tt testContext) {
tt.expect(tt.dialect.CreateTableSuffix()).To(matchers.Equal(""))
})

o.Spec("CreateIndexSuffix", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.CreateIndexSuffix()).To(matchers.Equal("using"))
o.Spec("CreateIndexSuffix", func(tt testContext) {
tt.expect(tt.dialect.CreateIndexSuffix()).To(matchers.Equal("using"))
})

o.Spec("DropIndexSuffix", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.DropIndexSuffix()).To(matchers.Equal(""))
o.Spec("DropIndexSuffix", func(tt testContext) {
tt.expect(tt.dialect.DropIndexSuffix()).To(matchers.Equal(""))
})

o.Spec("TruncateClause", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.TruncateClause()).To(matchers.Equal("truncate"))
o.Spec("TruncateClause", func(tt testContext) {
tt.expect(tt.dialect.TruncateClause()).To(matchers.Equal("truncate"))
})

o.Spec("SleepClause", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.SleepClause(1 * time.Second)).To(matchers.Equal("pg_sleep(1.000000)"))
expect(dialect.SleepClause(100 * time.Millisecond)).To(matchers.Equal("pg_sleep(0.100000)"))
o.Spec("SleepClause", func(tt testContext) {
tt.expect(tt.dialect.SleepClause(1 * time.Second)).To(matchers.Equal("pg_sleep(1.000000)"))
tt.expect(tt.dialect.SleepClause(100 * time.Millisecond)).To(matchers.Equal("pg_sleep(0.100000)"))
})

o.Spec("BindVar", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.BindVar(0)).To(matchers.Equal("$1"))
expect(dialect.BindVar(4)).To(matchers.Equal("$5"))
o.Spec("BindVar", func(tt testContext) {
tt.expect(tt.dialect.BindVar(0)).To(matchers.Equal("$1"))
tt.expect(tt.dialect.BindVar(4)).To(matchers.Equal("$5"))
})

o.Group("QuoteField", func() {
o.Spec("By default, case is preserved", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.QuoteField("Foo")).To(matchers.Equal(`"Foo"`))
expect(dialect.QuoteField("bar")).To(matchers.Equal(`"bar"`))
o.Spec("By default, case is preserved", func(tt testContext) {
tt.expect(tt.dialect.QuoteField("Foo")).To(matchers.Equal(`"Foo"`))
tt.expect(tt.dialect.QuoteField("bar")).To(matchers.Equal(`"bar"`))
})

o.Group("With LowercaseFields set to true", func() {
o.BeforeEach(func(expect expect.Expectation, dialect gorp.PostgresDialect) (expect.Expectation, gorp.PostgresDialect) {
dialect.LowercaseFields = true
return expect, dialect
o := onpar.BeforeEach(o, func(tt testContext) testContext {
tt.dialect.LowercaseFields = true
return tt
})

o.Spec("fields are lowercased", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.QuoteField("Foo")).To(matchers.Equal(`"foo"`))
o.Spec("fields are lowercased", func(tt testContext) {
tt.expect(tt.dialect.QuoteField("Foo")).To(matchers.Equal(`"foo"`))
})
})
})

o.Group("QuotedTableForQuery", func() {
o.Spec("using the default schema", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.QuotedTableForQuery("", "foo")).To(matchers.Equal(`"foo"`))
o.Spec("using the default schema", func(tt testContext) {
tt.expect(tt.dialect.QuotedTableForQuery("", "foo")).To(matchers.Equal(`"foo"`))
})

o.Spec("with a supplied schema", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.QuotedTableForQuery("foo", "bar")).To(matchers.Equal(`foo."bar"`))
o.Spec("with a supplied schema", func(tt testContext) {
tt.expect(tt.dialect.QuotedTableForQuery("foo", "bar")).To(matchers.Equal(`foo."bar"`))
})
})

o.Spec("IfSchemaNotExists", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.IfSchemaNotExists("foo", "bar")).To(matchers.Equal("foo if not exists"))
o.Spec("IfSchemaNotExists", func(tt testContext) {
tt.expect(tt.dialect.IfSchemaNotExists("foo", "bar")).To(matchers.Equal("foo if not exists"))
})

o.Spec("IfTableExists", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.IfTableExists("foo", "bar", "baz")).To(matchers.Equal("foo if exists"))
o.Spec("IfTableExists", func(tt testContext) {
tt.expect(tt.dialect.IfTableExists("foo", "bar", "baz")).To(matchers.Equal("foo if exists"))
})

o.Spec("IfTableNotExists", func(expect expect.Expectation, dialect gorp.PostgresDialect) {
expect(dialect.IfTableNotExists("foo", "bar", "baz")).To(matchers.Equal("foo if not exists"))
o.Spec("IfTableNotExists", func(tt testContext) {
tt.expect(tt.dialect.IfTableNotExists("foo", "bar", "baz")).To(matchers.Equal("foo if not exists"))
})
}
Loading