1// Copyright 2016 The etcd Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package e2e 16 17import ( 18 "os" 19 "strings" 20 "testing" 21 22 "github.com/coreos/etcd/pkg/expect" 23) 24 25var ( 26 defaultGatewayEndpoint = "127.0.0.1:23790" 27) 28 29func TestGateway(t *testing.T) { 30 ec, err := newEtcdProcessCluster(&configNoTLS) 31 if err != nil { 32 t.Fatal(err) 33 } 34 defer ec.StopAll() 35 36 eps := strings.Join(ec.grpcEndpoints(), ",") 37 38 p := startGateway(t, eps) 39 defer p.Stop() 40 41 os.Setenv("ETCDCTL_API", "3") 42 defer os.Unsetenv("ETCDCTL_API") 43 44 err = spawnWithExpect([]string{ctlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n") 45 if err != nil { 46 t.Errorf("failed to finish put request through gateway: %v", err) 47 } 48} 49 50func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess { 51 p, err := expect.NewExpect(binPath, "gateway", "--endpoints="+endpoints, "start") 52 if err != nil { 53 t.Fatal(err) 54 } 55 _, err = p.Expect("tcpproxy: ready to proxy client requests to") 56 if err != nil { 57 t.Fatal(err) 58 } 59 return p 60} 61