-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(template): Add & Update Tests; Rewrite Helper funcs; Updates #45
- Loading branch information
1 parent
4f9d978
commit 89cab85
Showing
4 changed files
with
64 additions
and
7 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Usage: fakedata [option ...] field... | ||
|
||
-f, --format string generators rows in f format. Available formats: csv|tab|sql | ||
-g, --generators lists available generators | ||
-l, --limit int limits rows up to n (default 10) | ||
-t, --table string table name of the sql format (default "TABLE") | ||
-v, --version shows version information | ||
-f, --format string generators rows in f format. Available formats: csv|tab|sql | ||
-g, --generators lists available generators | ||
-l, --limit int limits rows up to n (default 10) | ||
-t, --table string table name of the sql format (default "TABLE") | ||
--template string Use template as input | ||
-v, --version shows version information |
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,48 @@ | ||
package fakedata | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCreateConstraints(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input []string | ||
want string | ||
}{ | ||
{"two integers", []string{"1", "100"}, "1..100"}, | ||
{"three word enum constraints", []string{"feat", "issue", "docs"}, "feat..issue..docs"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := createConstraints(tt.input); got != tt.want { | ||
t.Errorf("template.createConstraints = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGetTemplateNameFromPath(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
want string | ||
}{ | ||
{"one word template name", "template.tmpl", "template.tmpl"}, | ||
{"absolute template path (unix)", "/var/www/home.tmpl", "home.tmpl"}, | ||
{"absolute template path (Windows)", "C:\\Data\\Templates\\test.tmpl", "test.tmpl"}, | ||
{"relative template path (Unix)", "./views/user/account.tmpl", "account.tmpl"}, | ||
{"relative template path (Windows)", "views\\user\\account.tmpl", "account.tmpl"}, | ||
{"spaced template path (Unix)", "./views/user account/account.tmpl", "account.tmpl"}, | ||
{"spaced template path (Windows)", "views\\user account\\account.tmpl", "account.tmpl"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := getTemplateNameFromPath(tt.input); got != tt.want { | ||
t.Errorf("template.getTemplateNameFromPath = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |