Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lann Martin
committed
Feb 9, 2014
1 parent
e25457a
commit e91e317
Showing
8 changed files
with
74 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ go: | |
- 1.1 | ||
- 1.2 | ||
- tip | ||
|
||
install: | ||
- go get | ||
- go get github.com/stretchr/testify/assert |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
package squirrel | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestQuestion(t *testing.T) { | ||
sql := "x = ? AND y = ?" | ||
s, _ := Question.ReplacePlaceholders(sql) | ||
if s != sql { | ||
t.Errorf("expected %v, got %v", sql, s) | ||
} | ||
assert.Equal(t, sql, s) | ||
} | ||
|
||
func TestDollar(t *testing.T) { | ||
sql := "x = ? AND y = ?" | ||
s, _ := Dollar.ReplacePlaceholders(sql) | ||
expect := "x = $1 AND y = $2" | ||
if s != expect { | ||
t.Errorf("expected %v, got %v", expect, s) | ||
} | ||
assert.Equal(t, "x = $1 AND y = $2", s) | ||
} |
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
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 |
---|---|---|
@@ -1,24 +1,28 @@ | ||
package squirrel | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSelect(t *testing.T) { | ||
sql, _, _ := Select("test").ToSql() | ||
expectedSql := "SELECT test" | ||
if sql != sqlStr { | ||
t.Errorf("expected %v, got %v", expectedSql, sql) | ||
} | ||
assert.Equal(t, "SELECT test", sql) | ||
} | ||
|
||
func TestStatementBuilder(t *testing.T) { | ||
db := &DBStub{} | ||
sb := StatementBuilder.RunWith(db) | ||
|
||
expectedSql := "SELECT test" | ||
|
||
sb.Select("test").Exec() | ||
sql := db.LastExecSql | ||
if sql != sqlStr { | ||
t.Errorf("expected %v, got %v", expectedSql, sql) | ||
} | ||
assert.Equal(t, "SELECT test", db.LastExecSql) | ||
} | ||
|
||
func TestStatementBuilderPlaceholderFormat(t *testing.T) { | ||
db := &DBStub{} | ||
sb := StatementBuilder.RunWith(db).PlaceholderFormat(Dollar) | ||
|
||
sb.Select("test").Where("x = ?").Exec() | ||
assert.Equal(t, "SELECT test WHERE x = $1", db.LastExecSql) | ||
} |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
package squirrel | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStmtCacherPrepare(t *testing.T) { | ||
db := &DBStub{} | ||
sc := NewStmtCacher(db) | ||
query := "SELECT 1" | ||
|
||
sc.Prepare(query) | ||
lastSql := db.LastPrepareSql | ||
if lastSql != query { | ||
t.Errorf("expected %v, got %v", query, lastSql) | ||
} | ||
assert.Equal(t, query, db.LastPrepareSql) | ||
|
||
sc.Prepare(query) | ||
if db.PrepareCount != 1 { | ||
t.Errorf("expected 1 Prepare, got %d", db.PrepareCount) | ||
} | ||
assert.Equal(t, 1, db.PrepareCount, "expected 1 Prepare, got %d", db.PrepareCount) | ||
} |
Oops, something went wrong.