-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Table and Column Stringer implementation (#14)
- Loading branch information
1 parent
ed3c04c
commit 8ef750f
Showing
4 changed files
with
170 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fizz_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gobuffalo/fizz" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Column_Stringer(t *testing.T) { | ||
t.Run("primary column", func(tt *testing.T) { | ||
r := require.New(tt) | ||
c := fizz.Column{ | ||
Name: "pk", | ||
ColType: "int", | ||
Primary: true, | ||
} | ||
|
||
r.Equal(`t.Column("pk", "int", {primary: true})`, c.String()) | ||
}) | ||
|
||
t.Run("simple column", func(tt *testing.T) { | ||
r := require.New(tt) | ||
c := fizz.Column{ | ||
Name: "name", | ||
ColType: "string", | ||
} | ||
|
||
r.Equal(`t.Column("name", "string")`, c.String()) | ||
}) | ||
|
||
t.Run("with option", func(tt *testing.T) { | ||
r := require.New(tt) | ||
c := fizz.Column{ | ||
Name: "alive", | ||
ColType: "boolean", | ||
Options: map[string]interface{}{ | ||
"null": true, | ||
}, | ||
} | ||
|
||
r.Equal(`t.Column("alive", "boolean", {null: true})`, c.String()) | ||
}) | ||
|
||
t.Run("with string option", func(tt *testing.T) { | ||
r := require.New(tt) | ||
c := fizz.Column{ | ||
Name: "price", | ||
ColType: "numeric", | ||
Options: map[string]interface{}{ | ||
"default": "1.00", | ||
}, | ||
} | ||
|
||
r.Equal(`t.Column("price", "numeric", {default: "1.00"})`, c.String()) | ||
}) | ||
} |
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,71 @@ | ||
package fizz_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gobuffalo/fizz" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Table_Stringer(t *testing.T) { | ||
r := require.New(t) | ||
|
||
expected := | ||
`create_table("users") { | ||
t.Column("name", "string") | ||
t.Column("alive", "boolean", {null: true}) | ||
t.Column("birth_date", "timestamp", {null: true}) | ||
t.Column("bio", "text", {null: true}) | ||
t.Column("price", "numeric", {default: "1.00", null: true}) | ||
t.Column("email", "string", {default: "[email protected]", size: 50}) | ||
}` | ||
|
||
table := fizz.Table{ | ||
Name: "users", | ||
Columns: []fizz.Column{ | ||
fizz.Column{ | ||
Name: "name", | ||
ColType: "string", | ||
}, | ||
fizz.Column{ | ||
Name: "alive", | ||
ColType: "boolean", | ||
Options: map[string]interface{}{ | ||
"null": true, | ||
}, | ||
}, | ||
fizz.Column{ | ||
Name: "birth_date", | ||
ColType: "timestamp", | ||
Options: map[string]interface{}{ | ||
"null": true, | ||
}, | ||
}, | ||
fizz.Column{ | ||
Name: "bio", | ||
ColType: "text", | ||
Options: map[string]interface{}{ | ||
"null": true, | ||
}, | ||
}, | ||
fizz.Column{ | ||
Name: "price", | ||
ColType: "numeric", | ||
Options: map[string]interface{}{ | ||
"null": true, | ||
"default": "1.00", | ||
}, | ||
}, | ||
fizz.Column{ | ||
Name: "email", | ||
ColType: "string", | ||
Options: map[string]interface{}{ | ||
"size": 50, | ||
"default": "[email protected]", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
r.Equal(expected, table.String()) | ||
} |