This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/return cas #44
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a458b88
insert and upsert cas return
hajnalandor 8392d3b
Merge branch 'develop' into feature/return-cas
hajnalandor e5b7c13
Merge branch 'develop' into feature/return-cas
hajnalandor 5848485
Merge branch 'develop' into feature/return-cas
hajnalandor 2cceb1e
rename CAS to Cas
hajnalandor acc4059
rewrite error messages
hajnalandor 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 |
---|---|---|
|
@@ -13,15 +13,16 @@ import ( | |
) | ||
|
||
func TestWrite(t *testing.T) { | ||
if _, id, err := testInsert(); err != nil || id == "" { | ||
_, id, err := testInsert() | ||
if err != nil || id == "" { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestWriteCustomID(t *testing.T) { | ||
cID := xid.New().String() + "Faswwq123942390**12312_+" | ||
ws := generate() | ||
id, err := th.Insert(context.Background(), "webshop", cID, &ws) | ||
_, id, err := th.Insert(context.Background(), "webshop", cID, &ws) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
@@ -30,41 +31,53 @@ func TestWriteCustomID(t *testing.T) { | |
|
||
func TestWritePtrValue(t *testing.T) { | ||
ws := generate() | ||
id, err := th.Insert(context.Background(), "webshop", "", &ws) | ||
cas, id, err := th.Insert(context.Background(), "webshop", "", &ws) | ||
if err != nil || id == "" { | ||
t.Fatal(err) | ||
} | ||
if len(cas) != 3 { | ||
t.Error("error") | ||
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. Provide better error something like, |
||
} | ||
} | ||
|
||
func TestWritePrimitivePtr(t *testing.T) { | ||
asd := "asd" | ||
s := struct { | ||
Name *string `json:"name,omitempty"` | ||
}{Name: &asd} | ||
id, err := th.Insert(context.Background(), "webshop", "", s) | ||
cas, id, err := th.Insert(context.Background(), "webshop", "", s) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
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. Same error here |
||
} | ||
} | ||
|
||
func TestWritePrimitivePtrNil(t *testing.T) { | ||
s := struct { | ||
Name *string `json:"name,omitempty"` | ||
}{} | ||
id, err := th.Insert(context.Background(), "webshop", "", s) | ||
cas, id, err := th.Insert(context.Background(), "webshop", "", s) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
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. Same error here |
||
} | ||
} | ||
|
||
func TestWriteNonExportedField(t *testing.T) { | ||
s := struct { | ||
name string | ||
}{name: "Jackson"} | ||
id, err := th.Insert(context.Background(), "member", "", s) | ||
cas, id, err := th.Insert(context.Background(), "member", "", s) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
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. Same error here |
||
} | ||
} | ||
|
||
func TestWriteExpectDuplicateError(t *testing.T) { | ||
|
@@ -73,11 +86,11 @@ func TestWriteExpectDuplicateError(t *testing.T) { | |
}{name: "Jackson"} | ||
ctx := context.Background() | ||
id := xid.New().String() | ||
_, err := th.Insert(ctx, "member", id, s) | ||
_, _, err := th.Insert(ctx, "member", id, s) | ||
if err != nil { | ||
t.Error("Missing error") | ||
} | ||
_, errDuplicateInsert := th.Insert(ctx, "member", id, s) | ||
_, _, errDuplicateInsert := th.Insert(ctx, "member", id, s) | ||
if errDuplicateInsert == nil { | ||
t.Error("error missing", errDuplicateInsert) | ||
} | ||
|
@@ -86,7 +99,7 @@ func TestWriteExpectDuplicateError(t *testing.T) { | |
|
||
func testInsert() (webshop, string, error) { | ||
ws := generate() | ||
id, err := th.Insert(context.Background(), "webshop", "", ws) | ||
_, id, err := th.Insert(context.Background(), "webshop", "", ws) | ||
return ws, id, err | ||
} | ||
|
||
|
@@ -109,7 +122,7 @@ func TestReadPrimitivePtrNil(t *testing.T) { | |
Job *string `json:"name,omitempty"` | ||
} | ||
test := wtyp{Job: &a} | ||
id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
_, id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
if errInsert != nil { | ||
t.Error("Error") | ||
} | ||
|
@@ -127,7 +140,7 @@ func TestReadPrimitivePtr(t *testing.T) { | |
Job *string `json:"name,omitempty"` | ||
} | ||
test := wtyp{Job: &a} | ||
id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
_, id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
if errInsert != nil { | ||
t.Error("Error") | ||
} | ||
|
@@ -146,7 +159,7 @@ func TestReadNonPointerInput(t *testing.T) { | |
Job *string `json:"name,omitempty"` | ||
} | ||
test := wtyp{Job: &a} | ||
id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
_, id, errInsert := th.Insert(context.Background(), "webshop", "", test) | ||
if errInsert != nil { | ||
t.Error("Error") | ||
} | ||
|
@@ -164,7 +177,7 @@ func TestReadNonExportedField(t *testing.T) { | |
job string | ||
} | ||
testInsert := wtyp{job: a} | ||
id, errInsert := th.Insert(context.Background(), "webshop", "", testInsert) | ||
_, id, errInsert := th.Insert(context.Background(), "webshop", "", testInsert) | ||
if errInsert != nil { | ||
t.Error("Error") | ||
} | ||
|
@@ -259,21 +272,24 @@ func TestUpsertSameID(t *testing.T) { | |
|
||
func TestUpsertPtrValueNewID(t *testing.T) { | ||
ws := generate() | ||
id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), &ws, 0) | ||
cas, id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), &ws, 0) | ||
if err != nil || id == "" { | ||
t.Fatal(err) | ||
} | ||
if len(cas) != 3 { | ||
t.Error("error") | ||
} | ||
} | ||
|
||
func TestUpsertPtrValueSameID(t *testing.T) { | ||
ws := generate() | ||
id := xid.New().String() | ||
_, err := th.Upsert(context.Background(), "webshop", id, &ws, 0) | ||
_, _, err := th.Upsert(context.Background(), "webshop", id, &ws, 0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wsD := generate() | ||
_, errD := th.Upsert(context.Background(), "webshop", id, &wsD, 1) | ||
_, _, errD := th.Upsert(context.Background(), "webshop", id, &wsD, 1) | ||
if errD != nil { | ||
t.Fatal(errD) | ||
} | ||
|
@@ -289,30 +305,39 @@ func TestUpsertPrimitivePtr(t *testing.T) { | |
s := struct { | ||
Name *string `json:"name,omitempty"` | ||
}{Name: &asd} | ||
id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
cas, id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
} | ||
} | ||
|
||
func TestUpsertPrimitivePtrNil(t *testing.T) { | ||
s := struct { | ||
Name *string `json:"name,omitempty"` | ||
}{} | ||
id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
cas, id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
} | ||
} | ||
|
||
func TestUpsertNonExportedField(t *testing.T) { | ||
s := struct { | ||
name string | ||
}{name: "Jackson"} | ||
id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
cas, id, err := th.Upsert(context.Background(), "webshop", xid.New().String(), s, 0) | ||
if err != nil || id == "" { | ||
t.Error("Missing error") | ||
} | ||
if len(cas) != 1 { | ||
t.Error("error") | ||
} | ||
} | ||
|
||
func TestUpsertEmptyID(t *testing.T) { | ||
|
@@ -327,7 +352,7 @@ func TestUpsertEmptyID(t *testing.T) { | |
|
||
func testUpsert(id string) (webshop, string, error) { | ||
ws := generate() | ||
id, err := th.Upsert(context.Background(), "webshop", id, ws, 0) | ||
_, id, err := th.Upsert(context.Background(), "webshop", id, ws, 0) | ||
return ws, id, err | ||
} | ||
|
||
|
@@ -352,14 +377,14 @@ func BenchmarkInsertEmb(b *testing.B) { | |
|
||
func BenchmarkInsert(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_, _ = th.Insert(context.Background(), "webshop", "", generate()) | ||
_, _, _ = th.Insert(context.Background(), "webshop", "", generate()) | ||
} | ||
} | ||
|
||
func BenchmarkGetSingle(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
startInsert := time.Now() | ||
ID, _ := th.Insert(context.Background(), "webshop", "", generate()) | ||
_, ID, _ := th.Insert(context.Background(), "webshop", "", generate()) | ||
fmt.Printf("Insert: %vns\tGet: ", time.Since(startInsert).Nanoseconds()) | ||
start := time.Now() | ||
_ = th.Get(context.Background(), "webshop", ID, webshop{}) | ||
|
@@ -386,7 +411,7 @@ func BenchmarkGetPtr(b *testing.B) { | |
for i := 0; i < b.N; i++ { | ||
job := jobtyp{Job: &j} | ||
startInsert := time.Now() | ||
id, _ := th.Insert(context.Background(), "job", "", job) | ||
_, id, _ := th.Insert(context.Background(), "job", "", job) | ||
fmt.Printf("Insert: %vns\tGet: ", time.Since(startInsert).Nanoseconds()) | ||
var jobRead jobtyp | ||
start := time.Now() | ||
|
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.
Rename to
Cas