Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update dashboard URL detection logic for DashboardCmd test #10509

Merged
merged 6 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package integration

import (
"bufio"
"bytes"
"context"
"encoding/json"
Expand Down Expand Up @@ -546,22 +547,24 @@ func validateStatusCmd(ctx context.Context, t *testing.T, profile string) {
func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

mctx, cancel := context.WithTimeout(ctx, Seconds(300))
defer cancel()

args := []string{"dashboard", "--url", "-p", profile, "--alsologtostderr", "-v=1"}
ss, err := Start(t, exec.CommandContext(ctx, Target(), args...))
ss, err := Start(t, exec.CommandContext(mctx, Target(), args...))
if err != nil {
t.Errorf("failed to run minikube dashboard. args %q : %v", args, err)
}
defer func() {
ss.Stop(t)
}()

start := time.Now()
s, err := ReadLineWithTimeout(ss.Stdout, Seconds(300))
s, err := dashboardURL(ss.Stdout)
if err != nil {
if runtime.GOOS == "windows" {
t.Skipf("failed to read url within %s: %v\noutput: %q\n", time.Since(start), err, s)
t.Skip(err)
}
t.Fatalf("failed to read url within %s: %v\noutput: %q\n", time.Since(start), err, s)
t.Fatal(err)
}

u, err := url.Parse(strings.TrimSpace(s))
Expand All @@ -583,6 +586,24 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) {
}
}

// dashboardURL gets the dashboard URL from the command stdout.
func dashboardURL(b *bufio.Reader) (string, error) {
// match http://127.0.0.1:XXXXX/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
dashURLRegexp := regexp.MustCompile(`^http:\/\/127\.0\.0\.1:[0-9]{5}\/api\/v1\/namespaces\/kubernetes-dashboard\/services\/http:kubernetes-dashboard:\/proxy\/$`)

s := bufio.NewScanner(b)
for s.Scan() {
t := s.Text()
if dashURLRegexp.MatchString(t) {
return t, nil
}
}
if err := s.Err(); err != nil {
return "", fmt.Errorf("failed reading input: %v", err)
}
return "", fmt.Errorf("output didn't produce a URL")
}

// validateDryRun asserts that the dry-run mode quickly exits with the right code
func validateDryRun(ctx context.Context, t *testing.T, profile string) {
// dry-run mode should always be able to finish quickly (<5s)
Expand Down
25 changes: 0 additions & 25 deletions test/integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,6 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
)

// ReadLineWithTimeout reads a line of text from a buffer with a timeout
func ReadLineWithTimeout(b *bufio.Reader, timeout time.Duration) (string, error) {
s := make(chan string)
e := make(chan error)
go func() {
read, err := b.ReadString('\n')
if err != nil {
e <- err
} else {
s <- read
}
close(s)
close(e)
}()

select {
case line := <-s:
return line, nil
case err := <-e:
return "", err
case <-time.After(timeout):
return "", fmt.Errorf("timeout after %s", timeout)
}
}

// UniqueProfileName returns a reasonably unique profile name
func UniqueProfileName(prefix string) string {
if *forceProfile != "" {
Expand Down