Skip to content

Commit

Permalink
Merge pull request #3 from usk81/fix_test
Browse files Browse the repository at this point in the history
fix test
  • Loading branch information
usk81 committed Jul 19, 2018
2 parents 47ae6ac + 343eb95 commit 3c73c94
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: go
go:
- "1.4"
- "1.5"
- "1.6"
- "1.7"
- "1.8"
- "1.9"
- "1.10"
- tip
before_install:
- go get github.com/axw/gocov/gocov
Expand Down
7 changes: 7 additions & 0 deletions type_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ type String struct {
string string
}

// MarshalString return generic.String converting of request data
func MarshalString(x interface{}) (String, error) {
v := String{}
err := v.Scan(x)
return v, err
}

// Value implements the driver Valuer interface.
func (v String) Value() (driver.Value, error) {
if !v.Valid() {
Expand Down
16 changes: 16 additions & 0 deletions type_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ type TestStringStruct struct {
NullValue String `json:"null_value"`
}

func TestMarshalString(t *testing.T) {
expected := String{
ValidFlag: true,
string: "foobar",
}

s := "foobar"
actual, err := MarshalString(s)
if err != nil {
t.Errorf("Not Expected error when MarshalString. error:%v", err.Error())
}
if actual != expected {
t.Errorf("actual:%v, expected:%v", actual, expected)
}
}

func TestStringJsonUnmarshalAndMarshal(t *testing.T) {
var ts TestStringStruct
jstr := `{"int":10,"float":1.1,"bool":false,"string":"qwertyuiopkjhgv876","html":"https://golang.org/src/encoding/json/encode.go?h=float64Encoder&foo=bar#L409","null_value":null}`
Expand Down
2 changes: 1 addition & 1 deletion type_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestTimeJsonUnmarshal(t *testing.T) {
if !tt.Valid() {
t.Error("ValidFlag should be TRUE")
}
if tt.Time().String() != v.String() {
if tt.Time().Format(time.RFC3339) != v.Format(time.RFC3339) {
t.Errorf("actual:%v, expected:%v", tt.Time(), v)
}
}
Expand Down
2 changes: 1 addition & 1 deletion type_timestamp_nanoseconds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestTimestampNanoSetTime(t *testing.T) {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if tn.Weak() != expected.UnixNano() {
t.Errorf("actual:%d, expected:%d", tn.Weak(), expected)
t.Errorf("actual:%v, expected:%v", tn.Weak(), expected)
}
}

Expand Down

0 comments on commit 3c73c94

Please sign in to comment.