feat: Support --header for CLI commands to support proxies (#4008)

Fixes #3527.
This commit is contained in:
Kyle Carberry
2022-09-12 16:22:05 -05:00
committed by GitHub
parent 846dd999b7
commit a2098254cd
4 changed files with 80 additions and 2 deletions
+24
View File
@@ -2,9 +2,12 @@ package cli_test
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
@@ -129,4 +132,25 @@ func TestRoot(t *testing.T) {
require.Contains(t, output, buildinfo.Version(), "has version")
require.Contains(t, output, buildinfo.ExternalURL(), "has url")
})
t.Run("Header", func(t *testing.T) {
t.Parallel()
done := make(chan struct{})
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "wow", r.Header.Get("X-Testing"))
w.WriteHeader(http.StatusGone)
select {
case <-done:
close(done)
default:
}
}))
defer srv.Close()
buf := new(bytes.Buffer)
cmd, _ := clitest.New(t, "--header", "X-Testing=wow", "login", srv.URL)
cmd.SetOut(buf)
// This won't succeed, because we're using the login cmd to assert requests.
_ = cmd.Execute()
})
}