doctor

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2019 Google LLC

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

https://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.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterDiagnostic

type ClusterDiagnostic struct {
	// contains filtered or unexported fields
}

ClusterDiagnostic tests that the cluster's Kubernetes version and components are suitable for kf.

func NewClusterDiagnostic

func NewClusterDiagnostic(kubeClient kubernetes.Interface) *ClusterDiagnostic

NewClusterDiagnostic creates a new ClusterDiagnostic to validate the install pointed at by the client.

func (*ClusterDiagnostic) Diagnose

func (c *ClusterDiagnostic) Diagnose(d *Diagnostic)

Diagnose valiates the version and components of the current Kubernetes cluster.

type Diagnosable

type Diagnosable interface {
	Diagnose(d *Diagnostic)
}

Diagnosable provides a high-level way to indicate a resource can be diagnosed.

type Diagnostic

type Diagnostic struct {
	// contains filtered or unexported fields
}

Diagnostic is a basic test structure that runs and reports on nested tests. It's modeled after the testing package.

func NewDefaultDiagnostic

func NewDefaultDiagnostic() *Diagnostic

NewDefaultDiagnostic creates a diagnostic with the root name of "doctor" that reports to stdout.

func NewDiagnostic

func NewDiagnostic(name string, w io.Writer) *Diagnostic

NewDiagnostic creates a new diagnostic with the given name that reports to the given writer.

func (*Diagnostic) Error

func (d *Diagnostic) Error(args ...interface{})

Error is equivalent to Log followed by Fail.

func (*Diagnostic) Errorf

func (d *Diagnostic) Errorf(format string, args ...interface{})

Errorf is equivalent to Logf followed by Fail.

Example
d := NewDefaultDiagnostic()

d.Run("example", func(d *Diagnostic) {
	d.Errorf("%d", 42)
	d.Log("after")
})
Output:

=== RUN	doctor/example
=== LOG	doctor/example
42
after
--- FAIL: doctor/example

func (*Diagnostic) Fail

func (d *Diagnostic) Fail()

Fail marks the function as having failed.

func (*Diagnostic) FailNow

func (d *Diagnostic) FailNow()

FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). Execution will continue at the parent diagnostic. If FailNow is called on the root Diagnostic, the goroutine is not exited.

func (*Diagnostic) Failed

func (d *Diagnostic) Failed() bool

Failed reports whether the function has failed.

func (*Diagnostic) Fatal

func (d *Diagnostic) Fatal(args ...interface{})

Fatal is equivalent to Log followed by FailNow.

Example
d := NewDefaultDiagnostic()

d.Run("example", func(d *Diagnostic) {
	d.Log("before")
	d.Fatal("immediate exit")
	d.Log("after")
})
Output:

=== RUN	doctor/example
=== LOG	doctor/example
before
immediate exit
--- FAIL: doctor/example

func (*Diagnostic) Fatalf

func (d *Diagnostic) Fatalf(format string, args ...interface{})

Fatalf is equivalent to Logf followed by FailNow.

Example
d := NewDefaultDiagnostic()

d.Run("example", func(d *Diagnostic) {
	d.Fatalf("%d", 42)
	d.Log("after")
})
Output:

=== RUN	doctor/example
=== LOG	doctor/example
42
--- FAIL: doctor/example

func (*Diagnostic) GatedRun

func (d *Diagnostic) GatedRun(name string, f func(d *Diagnostic))

GatedRun only executes the test function if all prior tests succeeded. This is useful as a way to structure top-level tests into groups with a logical dependence.

Example
d := NewDefaultDiagnostic()

d.GatedRun("validate-db-creds", func(d *Diagnostic) {
	d.Error("bad creds")
})

d.GatedRun("validate-db-version", func(d *Diagnostic) {
	// never reached because the previous run failed
})
Output:

=== RUN	doctor/validate-db-creds
=== LOG	doctor/validate-db-creds
bad creds

--- FAIL: doctor/validate-db-creds

func (*Diagnostic) Helper

func (d *Diagnostic) Helper()

Helper is a dummy function to replicate the interface of testing

func (*Diagnostic) Log

func (d *Diagnostic) Log(args ...interface{})

Log formats its arguments using default formatting, analogous to Println, and records the text in the error log.

func (*Diagnostic) Logf

func (d *Diagnostic) Logf(format string, args ...interface{})

Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log.

Example
d := NewDefaultDiagnostic()

d.Run("example", func(d *Diagnostic) {
	d.Logf("only printed on failure %d", 42)
})
Output:

=== RUN	doctor/example
--- PASS: doctor/example

func (*Diagnostic) Name

func (d *Diagnostic) Name() string

Name returns the name of the Diagnostic.

func (*Diagnostic) Report

func (d *Diagnostic) Report()

Report creates a detailed testing style report for the execution.

Example
d := NewDefaultDiagnostic()

d.Run("good", func(d *Diagnostic) {
	d.Logf("only printed on failure %d", 42)
})

d.Run("bad", func(d *Diagnostic) {
	d.Run("no-issue", func(d *Diagnostic) {})
	d.Run("fails", func(d *Diagnostic) {
		d.Fail()
	})
})

fmt.Println("Final Report:")
d.Report()
Output:

=== RUN	doctor/good
--- PASS: doctor/good
=== RUN	doctor/bad
=== RUN	doctor/bad/no-issue
=== RUN	doctor/bad/fails
=== LOG	doctor/bad/fails
=== LOG	doctor/bad
--- FAIL: doctor/bad
    --- PASS: doctor/bad/no-issue
    --- FAIL: doctor/bad/fails
Final Report:
--- FAIL: doctor
    --- PASS: doctor/good
    --- FAIL: doctor/bad
        --- PASS: doctor/bad/no-issue
        --- FAIL: doctor/bad/fails

func (*Diagnostic) Run

func (d *Diagnostic) Run(name string, f func(d *Diagnostic))

Run creates and executes a sub-test with the given name.

Example
d := NewDefaultDiagnostic()

d.Run("sub-test-good", func(d *Diagnostic) {
	d.Log("no output")
})

d.Run("sub-test-bad", func(d *Diagnostic) {
	d.Error("output")
})
Output:

=== RUN	doctor/sub-test-good
--- PASS: doctor/sub-test-good
=== RUN	doctor/sub-test-bad
=== LOG	doctor/sub-test-bad
output

--- FAIL: doctor/sub-test-bad

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL