Skip to content

Commit

Permalink
Merge pull request etcd-io#16553 from ahrtr/lock_rest_20230908
Browse files Browse the repository at this point in the history
test: add test case to cover lock restful APIs
  • Loading branch information
ahrtr authored Sep 9, 2023
2 parents a13fc7e + 0b27aff commit 8011a53
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/e2e/v3_curl_lock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2023 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"encoding/json"
"fmt"

"testing"

"github.com/stretchr/testify/require"

"go.etcd.io/etcd/pkg/v3/expect"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestCurlV3LockOperations(t *testing.T) {
testCtl(t, testCurlV3LockOperations, withCfg(*e2e.NewConfig(e2e.WithClusterSize(1))))
}

func testCurlV3LockOperations(cx ctlCtx) {
// lock
lockReq, err := json.Marshal(&v3lockpb.LockRequest{Name: []byte("lock1")})
require.NoError(cx.t, err)

clus := cx.epc
args := e2e.CURLPrefixArgsCluster(clus.Cfg, clus.Procs[0], "POST", e2e.CURLReq{
Endpoint: "/v3/lock/lock",
Value: string(lockReq),
})
resp, err := runCommandAndReadJsonOutput(args)
require.NoError(cx.t, err)
key, ok := resp["key"]
require.True(cx.t, ok)

// unlock
if err = e2e.CURLPost(cx.epc, e2e.CURLReq{
Endpoint: "/v3/lock/unlock",
Value: fmt.Sprintf(`{"key": "%v"}`, key),
Expected: expect.ExpectedResponse{Value: "revision"},
}); err != nil {
cx.t.Fatalf("testCurlV3LockOperations failed to execute unlock (%v)", err)
}
}

0 comments on commit 8011a53

Please sign in to comment.