-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sam Yuan <[email protected]>
- Loading branch information
1 parent
2c6f3a8
commit a19e2b0
Showing
2 changed files
with
115 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package trafficGenerator_test | ||
|
||
import ( | ||
"regexp" | ||
"strconv" | ||
"tape/pkg/infra/trafficGenerator" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Proposal", func() { | ||
Context("ConvertString", func() { | ||
It("work accordingly for string", func() { | ||
input := "data" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(data).To(Equal("data")) | ||
}) | ||
|
||
It("work accordingly for random str", func() { | ||
input := "randomString1" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(len(data)).To(Equal(1)) | ||
}) | ||
|
||
It("work accordingly for uuid", func() { | ||
input := "uuid" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(len(data) > 0).To(BeTrue()) | ||
}) | ||
|
||
It("work accordingly for randomNumber", func() { | ||
input := "randomNumber1_9" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(len(data)).To(Equal(1)) | ||
num, err := strconv.Atoi(data) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(num > 0).To(BeTrue()) | ||
}) | ||
|
||
It("work accordingly for string mix mode", func() { | ||
input := "{\"key\":\"randomNumber1_50\",\"key1\":\"randomNumber1_20\"}" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
regString, err := regexp.Compile("{\"key\":\"\\d*\",\"key1\":\"\\d*\"}") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(regString.MatchString(data)).To(BeTrue()) | ||
}) | ||
|
||
It("work accordingly for string mix mode 2", func() { | ||
input := "{\"k1\":\"uuid\",\"key2\":\"randomNumber10000_20000\",\"keys\":\"randomString10\"}" | ||
data, err := trafficGenerator.ConvertString(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
regString, err := regexp.Compile("{\"k1\":\".*\",\"key2\":\"\\d*\",\"keys\":\".*\"}") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(regString.MatchString(data)).To(BeTrue()) | ||
}) | ||
|
||
}) | ||
}) |