Skip to content

Commit

Permalink
Update test case to accept random spaces in case TestV3CurlTxn
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <wachao@vmware.com>
  • Loading branch information
ahrtr committed Aug 24, 2023
1 parent ed1f97b commit 4d2f3b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion pkg/expect/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
"os/exec"
"regexp"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -224,7 +225,16 @@ func (ep *ExpectProcess) ExpectFunc(ctx context.Context, f func(string) bool) (s

// ExpectWithContext returns the first line containing the given string.
func (ep *ExpectProcess) ExpectWithContext(ctx context.Context, s string) (string, error) {
return ep.ExpectFunc(ctx, func(txt string) bool { return strings.Contains(txt, s) })
return ep.ExpectFunc(ctx, func(txt string) bool {
if strings.Contains(txt, s) {
return true
}
r, err := regexp.Compile(s)
if err != nil {
return false
}
return r.MatchString(txt)
})
}

// Expect returns the first line containing the given string.
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ func testV3CurlTxn(cx ctlCtx) {
if jerr != nil {
cx.t.Fatal(jerr)
}
expected := `"succeeded":true,"responses":[{"response_put":{"header":{"revision":"2"}}}]`
expected := `.*"succeeded":true,\s*"responses":\[{"response_put":{"header":{"revision":"2"}}}].*`
p := cx.apiPrefix
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/kv/txn"), Value: string(jsonDat), Expected: expected}); err != nil {
cx.t.Fatalf("failed testV3CurlTxn txn with curl using prefix (%s) (%v)", p, err)
}

// was crashing etcd server
malformed := `{"compare":[{"result":0,"target":1,"key":"Zm9v","TargetUnion":null}],"success":[{"Request":{"RequestPut":{"key":"Zm9v","value":"YmFy"}}}]}`
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/kv/txn"), Value: malformed, Expected: `"code":3,"message":"etcdserver: key not found"`}); err != nil {
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/kv/txn"), Value: malformed, Expected: `.*"code":3,\s*"message":"etcdserver: key not found".*`}); err != nil {
cx.t.Fatalf("failed testV3CurlTxn put with curl using prefix (%s) (%v)", p, err)
}

Expand Down

0 comments on commit 4d2f3b2

Please sign in to comment.