Skip to content

Commit

Permalink
Increase coverage a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapette committed Apr 25, 2017
1 parent 661e9b1 commit ceff303
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/fakedata/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (f *SQLFormatter) Format(columns Columns, values []string) string {
sql := bytes.NewBufferString(fmt.Sprintf("INSERT INTO %s (", f.Table))

sql.WriteString(strings.Join(columns.names(), ","))
sql.WriteString(") values (")
sql.WriteString(") VALUES (")

formattedValues := make([]string, len(columns))
for i, value := range values {
Expand Down
48 changes: 48 additions & 0 deletions pkg/fakedata/formatter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fakedata_test

import (
"testing"

"github.com/lucapette/fakedata/pkg/fakedata"
)

var columns = fakedata.Columns{{Name: "name", Key: "name"}, {Name: "domain", Key: "domain"}}
var values = []string{"Grace Hopper", "example.com"}

func TestSeparatorFormatter(t *testing.T) {
tests := []struct {
name string
sep string
want string
}{
{"default", " ", "Grace Hopper example.com"},
{"csv", ",", "Grace Hopper,example.com"},
{"tab", "\t", "Grace Hopper\texample.com"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &fakedata.SeparatorFormatter{Separator: tt.sep}
if got := f.Format(columns, values); got != tt.want {
t.Errorf("SeparatorFormatter.Format() = %v, want %v", got, tt.want)
}
})
}
}

func TestSQLFormatter(t *testing.T) {
tests := []struct {
name string
table string
want string
}{
{"table answer", "ANSWER", "INSERT INTO ANSWER (name,domain) VALUES ('Grace Hopper','example.com');"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &fakedata.SQLFormatter{Table: tt.table}
if got := f.Format(columns, values); got != tt.want {
t.Errorf("SQLFormatter.Format() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit ceff303

Please sign in to comment.