-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue graphql.Time unmarshal time check #432 #438
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e457ff
time check for unix nanoseconds
panikgaul 4d6ae0d
Merge pull request #1 from panikgaul/panikgaul-patch-1
panikgaul 2077985
add unit tests for time functions
b0fb323
Merge pull request #2 from panikgaul/panikgaul-patch-2
panikgaul a159205
using fixed date and check the expected values
789e89a
Merge pull request #3 from panikgaul/panikgaul-patch-3
panikgaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,50 @@ | ||
package graphql | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
var timeTestCases = []interface{}{ | ||
time.Now(), | ||
int32(1), | ||
time.Now().Unix(), | ||
time.Now().UnixNano(), | ||
float64(-1), | ||
"2006-01-02T15:04:05Z", | ||
} | ||
|
||
func TestImplementsGraphQLType(t *testing.T) { | ||
time := Time{} | ||
if !time.ImplementsGraphQLType("Time") { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestUnmarshalGraphQL(t *testing.T) { | ||
var err error | ||
testTime := &Time{} | ||
|
||
for _, timeType := range timeTestCases { | ||
if err = testTime.UnmarshalGraphQL(timeType); err != nil { | ||
t.Fatalf("Failed to unmarshal %#v to Time: %s", timeType, err.Error()) | ||
} | ||
} | ||
|
||
if err = testTime.UnmarshalGraphQL(false); err == nil { | ||
t.Fatalf("Unmarshaling of %T to Time should be failed.", false) | ||
} | ||
} | ||
|
||
func TestMarshalJSON(t *testing.T) { | ||
exampleTime := "\"0001-01-01T00:00:00Z\"" | ||
testTime := &Time{} | ||
|
||
buf, err := testTime.MarshalJSON() | ||
if err != nil { | ||
t.Fatalf("Failed to marshal time to JSON: %s", err.Error()) | ||
} | ||
if string(buf) != exampleTime { | ||
t.Fatalf("Failed to marshal Time to JSON, expected %s, but instead got %s", exampleTime, buf) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, pelase, check the expected values too? So that each test has
got
,want
pair. This way you will not only check that marshalling and unmarshalling work but also that they return what you expect.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I wouldn't use
time.Now()
instead I prefer constants, pleaseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I added the checks for expeced values with assertion library and remove time.Now() usage.
Can you please check if it is ok for you, Thx!