Skip to content

Commit

Permalink
Began attempting to test JSON unsuccessfully
Browse files Browse the repository at this point in the history
  • Loading branch information
petergeorgas committed Apr 11, 2022
1 parent 6f49ed4 commit bdb3c41
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func ConvertType(t string, val interface{}) string {
switch t {
case "string":
return `'` + fmt.Sprintf("%v", val) + `'`
case "[]byte":
return `'` + fmt.Sprintf("%s", val) + `'`
default:
return fmt.Sprintf("%v", val)
}
Expand Down
53 changes: 53 additions & 0 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gofakeit

import (
"fmt"
"math/rand"
"testing"
)

Expand All @@ -24,6 +25,58 @@ func TestMultiSQLInsert(t *testing.T) {
// INSERT INTO People VALUES ('Markus', 'Moen', 21), ('Anibal', 'Kozey', 60), ('Sylvan', 'Mraz', 59);
}

func TestMultiSQLInsertJSON(t *testing.T) {

Seed(12)

AddFuncLookup("jsonperson", Info{
Category: "custom",
Description: "random JSON of a person",
Example: `{"first_name":"Bob", "last_name":"Jones"}`,
Output: "[]byte",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {

v, _ := JSON(&JSONOptions{
Type: "object",
RowCount: 1,
Fields: []Field{
{Name: "first_name", Function: "firstname"},
{Name: "last_name", Function: "lastname"},
},
})

return v, nil
},
})

type RandomPerson struct {
FakePerson []byte `fake:{jsonperson}"`
}

var f RandomPerson
Struct(&f)
fmt.Printf("%s\n", (f.FakePerson))
}

func TestMultiSQLInsertFloat(t *testing.T) {
Seed(11)

res, _ := SQLInsert(&SQLOptions{
Table: "People",
EntryCount: 3,
Fields: []Field{
{Name: "first_name", Function: "firstname"},
{Name: "last_name", Function: "lastname"},
{Name: "balance", Function: "float32"},
},
})

fmt.Println(string(res))

// Output:
// INSERT INTO People VALUES ('Markus', 'Moen', 2.7766049e+38), ('Anibal', 'Kozey', 3.8815667e+37), ('Sylvan', 'Mraz', 1.6268478e+38);
}

func TestMultiSQLInsertAutoincrement(t *testing.T) {
Seed(11)

Expand Down

0 comments on commit bdb3c41

Please sign in to comment.