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 <[email protected]>
  • Loading branch information
ahrtr committed Aug 24, 2023
1 parent ed1f97b commit c21db4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 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,24 @@ 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
}

s1 := s
if strings.HasPrefix(s1, "EXPR") {
s1 = s1[4:]
} else {
return false
}

r, err := regexp.Compile(s1)
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 := `EXPR.*"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: `EXPR.*"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 c21db4d

Please sign in to comment.