forked from redis/go-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
6b8c6b3
commit 681a1fe
Showing
4 changed files
with
127 additions
and
0 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,70 @@ | ||
package proto | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
type testScanSliceStruct struct { | ||
ID int | ||
Name string | ||
} | ||
|
||
func (this *testScanSliceStruct) MarshalBinary() (data []byte, err error) { | ||
return json.Marshal(data) | ||
} | ||
|
||
func (this *testScanSliceStruct) UnmarshalBinary(data []byte) error { | ||
return json.Unmarshal(data, this) | ||
} | ||
|
||
var _ = Describe("ScanSlice", func() { | ||
|
||
// Base string array for test. | ||
strAry := []string{`{"ID":-1,"Name":"Back Yu"}`, `{"ID":1,"Name":"szyhf"}`} | ||
// Validate json bytes of container if ScanSlice success | ||
equalJson := Equal([]byte(`[{"ID":-1,"Name":"Back Yu"},{"ID":1,"Name":"szyhf"}]`)) | ||
|
||
It("var testContainer []testScanSliceStruct", func() { | ||
var testContainer []testScanSliceStruct | ||
err := ScanSlice(strAry, &testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
jsonBytes, err := json.Marshal(testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(jsonBytes).Should(equalJson) | ||
}) | ||
|
||
It("testContainer := new([]testScanSliceStruct)", func() { | ||
testContainer := new([]testScanSliceStruct) | ||
err := ScanSlice(strAry, testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
jsonBytes, err := json.Marshal(testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(jsonBytes).Should(equalJson) | ||
}) | ||
|
||
It("var testContainer []*testScanSliceStruct", func() { | ||
var testContainer []*testScanSliceStruct | ||
err := ScanSlice(strAry, &testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
jsonBytes, err := json.Marshal(testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(jsonBytes).Should(equalJson) | ||
}) | ||
|
||
It("testContainer := new([]*testScanSliceStruct)", func() { | ||
testContainer := new([]*testScanSliceStruct) | ||
err := ScanSlice(strAry, testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
jsonBytes, err := json.Marshal(testContainer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(jsonBytes).Should(equalJson) | ||
}) | ||
|
||
}) |
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