-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…ing behavior The tiltfile evaluator always defaults the empty string to "localhost". We want to make sure that this goes down the default kubernetes binding codepath instead of our custom codepath to resolve hostnames. Fixes tilt-dev#5981 Signed-off-by: Nick Santos <nick.santos@docker.com>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/httpstream" | ||
) | ||
|
||
type fakeDialer struct { | ||
dialed bool | ||
conn httpstream.Connection | ||
err error | ||
negotiatedProtocol string | ||
} | ||
|
||
func (d *fakeDialer) Dial(protocols ...string) (httpstream.Connection, string, error) { | ||
d.dialed = true | ||
return d.conn, d.negotiatedProtocol, d.err | ||
} | ||
|
||
var fakeNewPodDialer = newPodDialerFn(func(namespace Namespace, podID PodID) (httpstream.Dialer, error) { | ||
return &fakeDialer{}, nil | ||
}) | ||
|
||
func TestPortForwardEmptyHost(t *testing.T) { | ||
client := portForwardClient{newPodDialer: fakeNewPodDialer} | ||
pf, err := client.CreatePortForwarder(context.Background(), "default", "podid", 8080, 8080, "") | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"127.0.0.1", "::1"}, pf.Addresses()) | ||
} | ||
|
||
func TestPortForwardLocalhost(t *testing.T) { | ||
client := portForwardClient{newPodDialer: fakeNewPodDialer} | ||
pf, err := client.CreatePortForwarder(context.Background(), "default", "podid", 8080, 8080, "localhost") | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"127.0.0.1", "::1"}, pf.Addresses()) | ||
} | ||
|
||
func TestPortForwardInvalidDomain(t *testing.T) { | ||
client := portForwardClient{newPodDialer: fakeNewPodDialer} | ||
_, err := client.CreatePortForwarder(context.Background(), "default", "podid", 8080, 8080, "domain.invalid") | ||
if assert.Error(t, err) { | ||
assert.Contains(t, err.Error(), "failed to look up address for domain.invalid") | ||
} | ||
} | ||
|
||
func TestPortForwardAllHosts(t *testing.T) { | ||
client := portForwardClient{newPodDialer: fakeNewPodDialer} | ||
pf, err := client.CreatePortForwarder(context.Background(), "default", "podid", 8080, 8080, "0.0.0.0") | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"0.0.0.0"}, pf.Addresses()) | ||
} | ||
|
||
func TestPortForwardIPv6Loopback(t *testing.T) { | ||
client := portForwardClient{newPodDialer: fakeNewPodDialer} | ||
pf, err := client.CreatePortForwarder(context.Background(), "default", "podid", 8080, 8080, "[::1]") | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"::1"}, pf.Addresses()) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.