mirror of https://github.com/k3s-io/k3s
test: End to end test for kubectl proxy --unix-socket
parent
f6da3fdbe1
commit
cd4f0b43ef
|
@ -21,7 +21,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -544,8 +546,35 @@ var _ = Describe("Kubectl client", func() {
|
||||||
Failf("Expected at least one supported apiversion, got %v", apiVersions)
|
Failf("Expected at least one supported apiversion, got %v", apiVersions)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
|
It("should support --unix-socket=/path", func() {
|
||||||
|
By("Starting the proxy")
|
||||||
|
tmpdir, err := ioutil.TempDir("", "kubectl-proxy-unix")
|
||||||
|
if err != nil {
|
||||||
|
Failf("Failed to create temporary directory: %v", err)
|
||||||
|
}
|
||||||
|
path := filepath.Join(tmpdir, "test")
|
||||||
|
defer os.Remove(path)
|
||||||
|
defer os.Remove(tmpdir)
|
||||||
|
cmd := kubectlCmd("proxy", fmt.Sprintf("--unix-socket=%s", path))
|
||||||
|
stdout, stderr, err := startCmdAndStreamOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
Failf("Failed to start kubectl command: %v", err)
|
||||||
|
}
|
||||||
|
defer stdout.Close()
|
||||||
|
defer stderr.Close()
|
||||||
|
defer tryKill(cmd)
|
||||||
|
buf := make([]byte, 128)
|
||||||
|
if _, err = stdout.Read(buf); err != nil {
|
||||||
|
Failf("Expected output from kubectl proxy: %v", err)
|
||||||
|
}
|
||||||
|
By("retrieving proxy /api/ output")
|
||||||
|
_, err = curlUnix("http://unused/api", path)
|
||||||
|
if err != nil {
|
||||||
|
Failf("Failed get of /api at %s: %v", path, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Checks whether the output split by line contains the required elements.
|
// Checks whether the output split by line contains the required elements.
|
||||||
|
@ -603,8 +632,19 @@ func startProxyServer() (int, *exec.Cmd, error) {
|
||||||
return -1, cmd, fmt.Errorf("Failed to parse port from proxy stdout: %s", output)
|
return -1, cmd, fmt.Errorf("Failed to parse port from proxy stdout: %s", output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func curl(addr string) (string, error) {
|
func curlUnix(url string, path string) (string, error) {
|
||||||
resp, err := http.Get(addr)
|
dial := func(proto, addr string) (net.Conn, error) {
|
||||||
|
return net.Dial("unix", path)
|
||||||
|
}
|
||||||
|
transport := &http.Transport{
|
||||||
|
Dial: dial,
|
||||||
|
}
|
||||||
|
return curlTransport(url, transport)
|
||||||
|
}
|
||||||
|
|
||||||
|
func curlTransport(url string, transport *http.Transport) (string, error) {
|
||||||
|
client := &http.Client{Transport: transport}
|
||||||
|
resp, err := client.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -616,6 +656,10 @@ func curl(addr string) (string, error) {
|
||||||
return string(body[:]), nil
|
return string(body[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func curl(url string) (string, error) {
|
||||||
|
return curlTransport(url, &http.Transport{})
|
||||||
|
}
|
||||||
|
|
||||||
func validateGuestbookApp(c *client.Client, ns string) {
|
func validateGuestbookApp(c *client.Client, ns string) {
|
||||||
Logf("Waiting for frontend to serve content.")
|
Logf("Waiting for frontend to serve content.")
|
||||||
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout, ns) {
|
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout, ns) {
|
||||||
|
|
Loading…
Reference in New Issue