Merge pull request #8041 from tstromberg/service-cmd-race
TestFunctional/parallel/ServiceCmd: Add loggingpull/8057/head
commit
4f194d21ba
|
@ -639,6 +639,30 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
|
||||||
|
|
||||||
// validateServiceCmd asserts basic "service" command functionality
|
// validateServiceCmd asserts basic "service" command functionality
|
||||||
func validateServiceCmd(ctx context.Context, t *testing.T, profile string) {
|
func validateServiceCmd(ctx context.Context, t *testing.T, profile string) {
|
||||||
|
defer func() {
|
||||||
|
if t.Failed() {
|
||||||
|
t.Logf("service test failed - dumping debug information")
|
||||||
|
|
||||||
|
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "describe", "po", "hello-node"))
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("%q failed: %v", rr.Command(), err)
|
||||||
|
}
|
||||||
|
t.Logf("hello-node pod describe:\n%s", rr.Stdout)
|
||||||
|
|
||||||
|
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "logs", "-l", "app=hello-node"))
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("%q failed: %v", rr.Command(), err)
|
||||||
|
}
|
||||||
|
t.Logf("hello-node logs:\n%s", rr.Stdout)
|
||||||
|
|
||||||
|
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "describe", "svc", "hello-node"))
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("%q failed: %v", rr.Command(), err)
|
||||||
|
}
|
||||||
|
t.Logf("hello-node svc describe:\n%s", rr.Stdout)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "deployment", "hello-node", "--image=k8s.gcr.io/echoserver:1.4"))
|
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "deployment", "hello-node", "--image=k8s.gcr.io/echoserver:1.4"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("%q failed: %v (may not be an error).", rr.Command(), err)
|
t.Logf("%q failed: %v (may not be an error).", rr.Command(), err)
|
||||||
|
@ -660,6 +684,11 @@ func validateServiceCmd(ctx context.Context, t *testing.T, profile string) {
|
||||||
t.Errorf("expected 'service list' to contain *hello-node* but got -%q-", rr.Stdout.String())
|
t.Errorf("expected 'service list' to contain *hello-node* but got -%q-", rr.Stdout.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "po", "hello-node"))
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("%q failed: %v (may not be an error)", rr.Command(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if NeedsPortForward() {
|
if NeedsPortForward() {
|
||||||
t.Skipf("test is broken for port-forwarded drivers: https://github.com/kubernetes/minikube/issues/7383")
|
t.Skipf("test is broken for port-forwarded drivers: https://github.com/kubernetes/minikube/issues/7383")
|
||||||
}
|
}
|
||||||
|
@ -691,31 +720,61 @@ func validateServiceCmd(ctx context.Context, t *testing.T, profile string) {
|
||||||
t.Errorf("expected 'service --format={{.IP}}' output to be -%q- but got *%q* . args %q.", u.Hostname(), rr.Stdout.String(), rr.Command())
|
t.Errorf("expected 'service --format={{.IP}}' output to be -%q- but got *%q* . args %q.", u.Hostname(), rr.Stdout.String(), rr.Command())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test a regular URLminikube
|
|
||||||
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "service", "hello-node", "--url"))
|
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "service", "hello-node", "--url"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to get service url. args: %q: %v", rr.Command(), err)
|
t.Errorf("failed to get service url. args: %q: %v", rr.Command(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = strings.TrimSpace(rr.Stdout.String())
|
endpoint = strings.TrimSpace(rr.Stdout.String())
|
||||||
|
t.Logf("found endpoint for hello-node: %s", endpoint)
|
||||||
|
|
||||||
u, err = url.Parse(endpoint)
|
u, err = url.Parse(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to parse %q: %v", endpoint, err)
|
t.Fatalf("failed to parse %q: %v", endpoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Scheme != "http" {
|
if u.Scheme != "http" {
|
||||||
t.Fatalf("expected scheme to be -%q- got scheme: *%q*", "http", u.Scheme)
|
t.Fatalf("expected scheme to be -%q- got scheme: *%q*", "http", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("url: %s", endpoint)
|
c := retryablehttp.NewClient()
|
||||||
resp, err := retryablehttp.Get(endpoint)
|
c.Logger = &logAdapter{t: t}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("get failed: %v\nresp: %v", err, resp)
|
t.Logf("Attempting to fetch %s ...", endpoint)
|
||||||
|
|
||||||
|
fetch := func() error {
|
||||||
|
resp, err := http.Get(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("error fetching %s: %v", endpoint, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("error reading body from %s: %v", endpoint, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Logf("%s: unexpected status code %d - body:\n%s", endpoint, resp.StatusCode, body)
|
||||||
|
} else {
|
||||||
|
t.Logf("%s: success! body:\n%s", endpoint, body)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
t.Fatalf("expected status code for %q to be -%q- but got *%q*", endpoint, http.StatusOK, resp.StatusCode)
|
if err = retry.Expo(fetch, 1*time.Second, Seconds(30)); err != nil {
|
||||||
|
t.Errorf("failed to fetch %s: %v", endpoint, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type logAdapter struct{ t *testing.T }
|
||||||
|
|
||||||
|
func (l *logAdapter) Printf(s string, args ...interface{}) {
|
||||||
|
l.t.Logf(s, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// validateAddonsCmd asserts basic "addon" command functionality
|
// validateAddonsCmd asserts basic "addon" command functionality
|
||||||
func validateAddonsCmd(ctx context.Context, t *testing.T, profile string) {
|
func validateAddonsCmd(ctx context.Context, t *testing.T, profile string) {
|
||||||
// Table output
|
// Table output
|
||||||
|
|
Loading…
Reference in New Issue