2016-07-22 02:01:54 +03:00
|
|
|
// Copyright 2016 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 (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2018-08-29 03:13:25 +03:00
|
|
|
"go.etcd.io/etcd/pkg/expect"
|
2016-07-22 02:01:54 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
defaultGatewayEndpoint = "127.0.0.1:23790"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGateway(t *testing.T) {
|
|
|
|
ec, err := newEtcdProcessCluster(&configNoTLS)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-07-15 02:03:04 +03:00
|
|
|
defer ec.Stop()
|
2016-07-22 02:01:54 +03:00
|
|
|
|
2017-07-15 02:03:04 +03:00
|
|
|
eps := strings.Join(ec.EndpointsV3(), ",")
|
2016-07-22 02:01:54 +03:00
|
|
|
|
|
|
|
p := startGateway(t, eps)
|
|
|
|
defer p.Stop()
|
|
|
|
|
|
|
|
os.Setenv("ETCDCTL_API", "3")
|
|
|
|
defer os.Unsetenv("ETCDCTL_API")
|
|
|
|
|
2016-08-04 18:51:20 +03:00
|
|
|
err = spawnWithExpect([]string{ctlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
|
2016-07-22 02:01:54 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to finish put request through gateway: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess {
|
2016-08-04 18:51:20 +03:00
|
|
|
p, err := expect.NewExpect(binPath, "gateway", "--endpoints="+endpoints, "start")
|
2016-07-22 02:01:54 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-04-17 04:25:30 +03:00
|
|
|
_, err = p.Expect("ready to proxy client requests")
|
2016-07-22 02:01:54 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|