pull/16278/head
Sarah Alsmiller 2 years ago
parent 60a62add31
commit 560cd55675

@ -1,6 +1,7 @@
package gateways_test package gateways_test
import ( import (
"bufio"
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
@ -11,8 +12,9 @@ import (
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils" "github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"os/exec" "net/http"
"strings" "os"
"strconv"
"testing" "testing"
"time" "time"
) )
@ -34,7 +36,7 @@ func TestAPIGatewayCreate(t *testing.T) {
Name: "api-gateway", Name: "api-gateway",
Listeners: []api.APIGatewayListener{ Listeners: []api.APIGatewayListener{
{ {
Port: 9999, Port: 8443,
Protocol: "tcp", Protocol: "tcp",
}, },
}, },
@ -62,23 +64,25 @@ func TestAPIGatewayCreate(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// Create a client proxy instance with the server as an upstream // Create a client proxy instance with the server as an upstream
clientConnectProxy := createServices(t, cluster) clientConnectProxy, gatewayService := createServices(t, cluster)
fmt.Println(clientConnectProxy) fmt.Println(clientConnectProxy)
agentUrl, err := cluster.Agents[0].GetPod().PortEndpoint(context.Background(), "8500", "http")
cmdStr := "consul connect envoy -gateway api -register -service api-gateway -proxy-id api-gateway -http-addr " + agentUrl //how to exec into the consul CLI
//agentUrl, err := cluster.Agents[0].GetPod().PortEndpoint(context.Background(), "8500", "http")
c := strings.Split(cmdStr, " ") //cmdStr := "consul connect envoy -gateway api -register -service api-gateway -proxy-id api-gateway -http-addr " + agentUrl
t.Log("------------\n\n\n") //
cmd := exec.Command(c[0], c[1:]...) //c := strings.Split(cmdStr, " ")
out := bytes.NewBufferString("") //t.Log("------------\n\n\n")
stdErr := bytes.NewBufferString("") //cmd := exec.Command(c[0], c[1:]...)
cmd.Stdout = out //out := bytes.NewBufferString("")
cmd.Stderr = stdErr //stdErr := bytes.NewBufferString("")
err = cmd.Run() //cmd.Stdout = out
t.Log(out) //cmd.Stderr = stdErr
t.Log(stdErr) //err = cmd.Run()
t.Log("------------\n\n\n") //t.Log(out)
assert.NoError(t, err) //t.Log(stdErr)
//t.Log("------------\n\n\n")
//assert.NoError(t, err)
//TODO this can and should be broken up more effectively, this is just proof of concept //TODO this can and should be broken up more effectively, this is just proof of concept
//check statuses //check statuses
@ -122,9 +126,31 @@ func TestAPIGatewayCreate(t *testing.T) {
t.Log(g) t.Log(g)
} }
for { t.Log(gatewayService.GetAddr())
assert.NoError(t, err)
fmt.Println(gatewayService)
ip, port := gatewayService.GetAddr()
t.Log("ip:", ip)
stdOut := bufio.NewWriter(os.Stdout)
stdOut.Write([]byte(ip + "\n"))
stdOut.Write([]byte(strconv.Itoa(port)))
stdOut.Flush()
resp, err := http.Get(fmt.Sprintf("http://%s:%d", ip, port))
t.Log(resp, err)
assert.NoError(t, err)
buf := bytes.NewBufferString("abcdefg")
resp, err = http.Post(fmt.Sprintf("http://%s:%d", ip, port), "text/plain", buf)
t.Log(resp, err)
for {
} }
//t.Log(gatewayService.Restart())
//t.Log(gatewayService.GetStatus())
//t.Log(gatewayService.GetLogs())
t.Fail()
} }
@ -174,10 +200,12 @@ func createCluster(t *testing.T) *libcluster.Cluster {
require.NoError(t, err) require.NoError(t, err)
require.True(t, ok) require.True(t, ok)
require.NoError(t, err)
return cluster return cluster
} }
func createServices(t *testing.T, cluster *libcluster.Cluster) libservice.Service { func createServices(t *testing.T, cluster *libcluster.Cluster) (libservice.Service, libservice.Service) {
node := cluster.Agents[0] node := cluster.Agents[0]
client := node.GetClient() client := node.GetClient()
// Create a service and proxy instance // Create a service and proxy instance
@ -201,5 +229,9 @@ func createServices(t *testing.T, cluster *libcluster.Cluster) libservice.Servic
libassert.CatalogServiceExists(t, client, "static-client-sidecar-proxy") libassert.CatalogServiceExists(t, client, "static-client-sidecar-proxy")
return clientConnectProxy gatewayService, err := libservice.NewGatewayService(context.Background(), "api-gateway", "api", cluster.Agents[0])
libassert.CatalogServiceExists(t, client, "api-gateway")
require.NoError(t, err)
return clientConnectProxy, gatewayService
} }

Loading…
Cancel
Save