-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address review comments, rip out go type parsing from config
- Loading branch information
1 parent
6400a47
commit 9c7d17d
Showing
9 changed files
with
162 additions
and
329 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
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,117 @@ | ||
package opts | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestTypeOverrides(t *testing.T) { | ||
for _, test := range []struct { | ||
override Override | ||
pkg string | ||
typeName string | ||
basic bool | ||
}{ | ||
{ | ||
Override{ | ||
DBType: "uuid", | ||
GoType: GoType{Spec: "github.com/segmentio/ksuid.KSUID"}, | ||
}, | ||
"github.com/segmentio/ksuid", | ||
"ksuid.KSUID", | ||
false, | ||
}, | ||
// TODO: Add test for struct pointers | ||
// | ||
// { | ||
// Override{ | ||
// DBType: "uuid", | ||
// GoType: "github.com/segmentio/*ksuid.KSUID", | ||
// }, | ||
// "github.com/segmentio/ksuid", | ||
// "*ksuid.KSUID", | ||
// false, | ||
// }, | ||
{ | ||
Override{ | ||
DBType: "citext", | ||
GoType: GoType{Spec: "string"}, | ||
}, | ||
"", | ||
"string", | ||
true, | ||
}, | ||
{ | ||
Override{ | ||
DBType: "timestamp", | ||
GoType: GoType{Spec: "time.Time"}, | ||
}, | ||
"time", | ||
"time.Time", | ||
false, | ||
}, | ||
} { | ||
tt := test | ||
t.Run(tt.override.GoType.Spec, func(t *testing.T) { | ||
if err := tt.override.Parse(); err != nil { | ||
t.Fatalf("override parsing failed; %s", err) | ||
} | ||
if diff := cmp.Diff(tt.pkg, tt.override.GoImportPath); diff != "" { | ||
t.Errorf("package mismatch;\n%s", diff) | ||
} | ||
if diff := cmp.Diff(tt.typeName, tt.override.GoTypeName); diff != "" { | ||
t.Errorf("type name mismatch;\n%s", diff) | ||
} | ||
if diff := cmp.Diff(tt.basic, tt.override.GoBasicType); diff != "" { | ||
t.Errorf("basic mismatch;\n%s", diff) | ||
} | ||
}) | ||
} | ||
for _, test := range []struct { | ||
override Override | ||
err string | ||
}{ | ||
{ | ||
Override{ | ||
DBType: "uuid", | ||
GoType: GoType{Spec: "Pointer"}, | ||
}, | ||
"Package override `go_type` specifier \"Pointer\" is not a Go basic type e.g. 'string'", | ||
}, | ||
{ | ||
Override{ | ||
DBType: "uuid", | ||
GoType: GoType{Spec: "untyped rune"}, | ||
}, | ||
"Package override `go_type` specifier \"untyped rune\" is not a Go basic type e.g. 'string'", | ||
}, | ||
} { | ||
tt := test | ||
t.Run(tt.override.GoType.Spec, func(t *testing.T) { | ||
err := tt.override.Parse() | ||
if err == nil { | ||
t.Fatalf("expected parse to fail; got nil") | ||
} | ||
if diff := cmp.Diff(tt.err, err.Error()); diff != "" { | ||
t.Errorf("error mismatch;\n%s", diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func FuzzOverride(f *testing.F) { | ||
for _, spec := range []string{ | ||
"string", | ||
"github.com/gofrs/uuid.UUID", | ||
"github.com/segmentio/ksuid.KSUID", | ||
} { | ||
f.Add(spec) | ||
} | ||
f.Fuzz(func(t *testing.T, s string) { | ||
o := Override{ | ||
GoType: GoType{Spec: s}, | ||
} | ||
o.Parse() | ||
}) | ||
} |
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
Oops, something went wrong.