Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from rusq/patch-1
Handle possible null in JSONTime Unmarshal.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package slack | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestJSONTime_UnmarshalJSON(t *testing.T) { | ||
type args struct { | ||
buf []byte | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantTr JSONTime | ||
wantErr bool | ||
}{ | ||
{ | ||
"acceptable int64 timestamp", | ||
args{[]byte(`1643435556`)}, | ||
JSONTime(1643435556), | ||
false, | ||
}, | ||
{ | ||
"acceptable string timestamp", | ||
args{[]byte(`"1643435556"`)}, | ||
JSONTime(1643435556), | ||
false, | ||
}, | ||
{ | ||
"null", | ||
args{[]byte(`null`)}, | ||
JSONTime(0), | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var tr JSONTime | ||
if err := tr.UnmarshalJSON(tt.args.buf); (err != nil) != tt.wantErr { | ||
t.Errorf("JSONTime.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |