This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix do option from empty context and add tests (#47)
* fix do option from empty context and add tests * set real coverage
- Loading branch information
Showing
3 changed files
with
77 additions
and
4 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
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,73 @@ | ||
package service_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/s7techlab/hlf-sdk-go/api" | ||
"github.com/s7techlab/hlf-sdk-go/client/chaincode" | ||
"github.com/s7techlab/hlf-sdk-go/client/chaincode/txwaiter" | ||
|
||
"github.com/s7techlab/cckit/gateway/service" | ||
) | ||
|
||
func TestContext(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Context Suite") | ||
} | ||
|
||
var ( | ||
doOptsEmpty = []api.DoOption{} | ||
doOptsAll = []api.DoOption{chaincode.WithTxWaiter(txwaiter.All)} | ||
doOptsSelf = []api.DoOption{chaincode.WithTxWaiter(txwaiter.Self)} | ||
) | ||
|
||
var _ = Describe(`DoOption`, func() { | ||
|
||
It("Set Default DoOption", func() { | ||
ctx := service.ContextWithDefaultDoOption(context.Background(), doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsSelf)) | ||
}) | ||
|
||
It("Default dont allow update on ctx DoOption", func() { | ||
ctx := service.ContextWithDefaultDoOption(context.Background(), doOptsAll...) | ||
ctx = service.ContextWithDefaultDoOption(ctx, doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsAll)) | ||
}) | ||
|
||
It("Set DoOption to Context", func() { | ||
ctx := service.ContextWithDoOption(context.Background(), doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsSelf)) | ||
}) | ||
|
||
It("Update DoOption to Context", func() { | ||
ctx := service.ContextWithDoOption(context.Background(), doOptsAll...) | ||
ctx = service.ContextWithDoOption(ctx, doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsSelf)) | ||
}) | ||
|
||
It("Update DoOption to Context", func() { | ||
ctx := service.ContextWithDoOption(context.Background(), doOptsAll...) | ||
ctx = service.ContextWithDoOption(ctx, doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsSelf)) | ||
}) | ||
|
||
It("Allow get DoOptions from empty Context", func() { | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsEmpty)) | ||
}) | ||
|
||
It("Allow get DoOptions from filled Context", func() { | ||
ctx := service.ContextWithDoOption(ctx, doOptsSelf...) | ||
result := service.DoOptionFromContext(ctx) | ||
Expect(result).To(Equal(doOptsSelf)) | ||
}) | ||
}) |