Added integration tests for proxy

pull/4229/head
Medya Gh 2019-05-15 15:00:45 -07:00
parent e878f9badb
commit 10799333f1
3 changed files with 104 additions and 0 deletions

2
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/docker/docker v0.0.0-20180917213351-bbe08dc7f0b9
github.com/docker/go-units v0.0.0-20170127094116-9e638d38cf69
github.com/docker/machine v0.16.1
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f
github.com/fsnotify/fsnotify v0.0.0-20160816051541-f12c6236fe7b
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680
github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e
@ -56,6 +57,7 @@ require (
github.com/pelletier/go-toml v0.0.0-20160822122712-0049ab3dc4c4
github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c
github.com/peterbourgon/diskv v2.0.1+incompatible
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/browser v0.0.0-20160118053552-9302be274faa
github.com/pkg/errors v0.8.0
github.com/pkg/profile v0.0.0-20161223203901-3a8809bd8a80

4
go.sum
View File

@ -19,6 +19,8 @@ github.com/docker/go-units v0.0.0-20170127094116-9e638d38cf69 h1:N4WAsrRIb+4U1yI
github.com/docker/go-units v0.0.0-20170127094116-9e638d38cf69/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/machine v0.16.1 h1:zrgroZounGVkxLmBqMyc1uT2GgapXVjIWHCfBf0udrA=
github.com/docker/machine v0.16.1/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI=
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f h1:8GDPb0tCY8LQ+OJ3dbHb5sA6YZWXFORQYZx5sdsTlMs=
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/fsnotify/fsnotify v0.0.0-20160816051541-f12c6236fe7b h1:lHoxUxMozh/yCASOoFep9dPMva62ztmxKK2VB8//Aoo=
github.com/fsnotify/fsnotify v0.0.0-20160816051541-f12c6236fe7b/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM=
@ -105,6 +107,8 @@ github.com/pelletier/go-toml v0.0.0-20160822122712-0049ab3dc4c4/go.mod h1:5z9KED
github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c/go.mod h1:HUpKUBZnpzkdx0kD/+Yfuft+uD3zHGtXF/XJB14TUr4=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
github.com/pkg/browser v0.0.0-20160118053552-9302be274faa h1:od00Tr1U7+cLVtc+RNFmR53spHUF98Ziu33S8UIQnt0=
github.com/pkg/browser v0.0.0-20160118053552-9302be274faa/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=

View File

@ -0,0 +1,98 @@
// +build integration
/*
Copyright 2019 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integration
import (
"context"
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/elazarl/goproxy"
"github.com/phayes/freeport"
"github.com/pkg/errors"
"net/http"
)
// setUpProxy runs a local http proxy and sets the env vars for it.
func setUpProxy() error {
port, err := freeport.GetFreePort()
if err != nil {
return errors.Wrap(err, "Failed to get an open port")
}
addr:= fmt.Sprintf("localhost:%d",port)
err = os.Setenv("NO_PROXY", "")
if err != nil {
return errors.Wrap(err, "Failed to set no proxy env")
}
err = os.Setenv("HTTP_PROXY", addr)
if err != nil {
return errors.Wrap(err, "Failed to set http proxy env")
}
proxy := goproxy.NewProxyHttpServer()
go func() error{ // TODO: handle error @medyagh
return errors.Wrap(http.ListenAndServe(addr, proxy), "Error serving http server for proxy")
}()
return nil
}
func TestProxy(t *testing.T) {
err := setUpProxy()
if err != nil {
t.Fatalf("Failed to set up the test proxy: %s", err)
}
t.Run("ConsoleWarnning", testProxyWarning)
t.Run("DashboardProxy", testDashboard)
}
// testProxyWarning checks user is warned correctly about the proxy related env vars
func testProxyWarning(t *testing.T) {
mk := NewMinikubeRunner(t)
// Start a timer for all remaining commands, to display failure output before a panic.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
startCmd := fmt.Sprintf("start %s %s %s", mk.StartArgs, mk.Args,
"--alsologtostderr --v=5")
stdout, stderr, err := mk.RunWithContext(ctx, startCmd)
if err != nil {
t.Fatalf("start: %v\nstdout: %s\nstderr: %s", err, stdout, stderr)
}
mk.EnsureRunning()
// Pre-cleanup: this usually fails, because no instance is running.
// mk.RunWithContext(ctx, "delete")
msg := "Found network options:"
if !strings.Contains(stdout, msg) {
t.Errorf("Proxy wranning (%s) is missing from the output: %s", msg, stderr)
}
msg = "You appear to be using a proxy"
if !strings.Contains(stderr, msg) {
t.Errorf("Proxy wranning (%s) is missing from the output: %s", msg, stderr)
}
}