-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
19 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 |
---|---|---|
@@ -1,29 +1,90 @@ | ||
package goriak | ||
|
||
import ( | ||
//riak "github.com/basho/riak-go-client" | ||
"errors" | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestMiddlewareSet(t *testing.T) { | ||
func TestMiddlewareSetAbort(t *testing.T) { | ||
m := func(cmd ExecMiddlewarer, next func() (*Result, error)) (*Result, error) { | ||
return nil, errors.New("aborted middleware") | ||
} | ||
|
||
_, err := Bucket("middleware", "tests"). | ||
SetRaw([]byte{1, 2, 3, 4, 5}). | ||
AddMiddleware(m). | ||
Run(con()) | ||
if err == nil { | ||
t.Error("no error") | ||
} | ||
|
||
if err.Error() != "aborted middleware" { | ||
t.Error("unexpected error") | ||
} | ||
} | ||
|
||
func TestMiddlewareSetKeyTest(t *testing.T) { | ||
beforeEmpty := 0 | ||
afterWithKey := 0 | ||
|
||
m := func(cmd ExecMiddlewarer, next func() (*Result, error)) (*Result, error) { | ||
log.Println("Middleware BEFORE:", cmd.GetKey()) | ||
return nil, errors.New("abort!") | ||
if cmd.Key() == "" { | ||
beforeEmpty++ | ||
} | ||
|
||
res, err := next() | ||
log.Println("Middleware After:", cmd.GetKey()) | ||
|
||
if cmd.Key() != "" { | ||
afterWithKey++ | ||
} | ||
|
||
return res, err | ||
} | ||
|
||
res, err := Bucket("middleware", "tests"). | ||
_, err := Bucket("middleware", "tests"). | ||
SetRaw([]byte{1, 2, 3, 4, 5}). | ||
///Key("abc123"). | ||
AddMiddleware(m). | ||
AddMiddleware(m). | ||
Run(con()) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if beforeEmpty != 2 { | ||
t.Error("wrong beforeEmpty count") | ||
} | ||
|
||
t.Log(res, err) | ||
if afterWithKey != 2 { | ||
t.Error("wrong afterWithKey count") | ||
} | ||
} | ||
|
||
func TestMiddlewareSetBucketType(t *testing.T) { | ||
m := func(cmd ExecMiddlewarer, next func() (*Result, error)) (*Result, error) { | ||
if cmd.Bucket() != "middleware" { | ||
t.Error("unexpected before bucket") | ||
} | ||
if cmd.BucketType() != "tests" { | ||
t.Error("unexpected before bucket type") | ||
} | ||
|
||
res, err := next() | ||
|
||
if cmd.Bucket() != "middleware" { | ||
t.Error("unexpected after bucket") | ||
} | ||
if cmd.BucketType() != "tests" { | ||
t.Error("unexpected after bucket type") | ||
} | ||
|
||
return res, err | ||
} | ||
|
||
_, err := Bucket("middleware", "tests"). | ||
SetRaw([]byte{1, 2, 3, 4, 5}). | ||
AddMiddleware(m). | ||
Run(con()) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
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