gateway_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. package e2e
  15. import (
  16. "os"
  17. "strings"
  18. "testing"
  19. "go.etcd.io/etcd/pkg/expect"
  20. )
  21. var (
  22. defaultGatewayEndpoint = "127.0.0.1:23790"
  23. )
  24. func TestGateway(t *testing.T) {
  25. ec, err := newEtcdProcessCluster(&configNoTLS)
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. defer ec.Stop()
  30. eps := strings.Join(ec.EndpointsV3(), ",")
  31. p := startGateway(t, eps)
  32. defer p.Stop()
  33. os.Setenv("ETCDCTL_API", "3")
  34. defer os.Unsetenv("ETCDCTL_API")
  35. err = spawnWithExpect([]string{ctlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
  36. if err != nil {
  37. t.Errorf("failed to finish put request through gateway: %v", err)
  38. }
  39. }
  40. func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess {
  41. p, err := expect.NewExpect(binPath, "gateway", "--endpoints="+endpoints, "start")
  42. if err != nil {
  43. t.Fatal(err)
  44. }
  45. _, err = p.Expect("ready to proxy client requests")
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. return p
  50. }