-
Notifications
You must be signed in to change notification settings - Fork 912
GODRIVER-2119 implement methods required to use as a map key #715
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,38 @@ func TestCounterOverflow(t *testing.T) { | |
require.Equal(t, uint32(0), objectIDCounter) | ||
} | ||
|
||
func TestObjectID_MarshalJSONMap(t *testing.T) { | ||
type mapOID struct { | ||
Map map[ObjectID]string | ||
} | ||
|
||
oid := NewObjectID() | ||
expectedJSON := []byte(fmt.Sprintf(`{"Map":{%q:"foo"}}`, oid.Hex())) | ||
data := mapOID{ | ||
Map: map[ObjectID]string{oid: "foo"}, | ||
} | ||
|
||
out, err := json.Marshal(&data) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedJSON, out) | ||
} | ||
|
||
func TestObjectID_UnmarshalJSONMap(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider incorporating this test function as a test case in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not add it in |
||
type mapOID struct { | ||
Map map[ObjectID]string | ||
} | ||
oid := NewObjectID() | ||
mapOIDJSON := []byte(fmt.Sprintf(`{"Map":{%q:"foo"}}`, oid.Hex())) | ||
expectedData := mapOID{ | ||
Map: map[ObjectID]string{oid: "foo"}, | ||
} | ||
|
||
data := mapOID{} | ||
err := json.Unmarshal(mapOIDJSON, &data) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedData, data) | ||
} | ||
benjirewis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func TestObjectID_UnmarshalJSON(t *testing.T) { | ||
oid := NewObjectID() | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.