mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Improve error behaviour of package coverage.
This commit is contained in:
parent
facce197b1
commit
13d1961d2b
@ -22,6 +22,7 @@ package coverage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"os"
|
"os"
|
||||||
@ -29,8 +30,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var flushInterval = 5 * time.Second
|
|
||||||
|
|
||||||
var coverageFile string
|
var coverageFile string
|
||||||
|
|
||||||
// tempCoveragePath returns a temporary file to write coverage information to.
|
// tempCoveragePath returns a temporary file to write coverage information to.
|
||||||
@ -48,9 +47,16 @@ func InitCoverage(name string) {
|
|||||||
if coverageFile == "" {
|
if coverageFile == "" {
|
||||||
coverageFile = "/tmp/k8s-" + name + ".cov"
|
coverageFile = "/tmp/k8s-" + name + ".cov"
|
||||||
}
|
}
|
||||||
|
fmt.Println("Dumping coverage information to " + coverageFile)
|
||||||
|
|
||||||
if duration, err := time.ParseDuration(os.Getenv("KUBE_COVERAGE_FLUSH_INTERVAL")); err == nil {
|
flushInterval := 5 * time.Second
|
||||||
flushInterval = duration
|
requestedInterval := os.Getenv("KUBE_COVERAGE_FLUSH_INTERVAL")
|
||||||
|
if requestedInterval != "" {
|
||||||
|
if duration, err := time.ParseDuration(requestedInterval); err == nil {
|
||||||
|
flushInterval = duration
|
||||||
|
} else {
|
||||||
|
panic("Invalid KUBE_COVERAGE_FLUSH_INTERVAL value; try something like '30s'.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the unit test framework with the required arguments to activate test coverage.
|
// Set up the unit test framework with the required arguments to activate test coverage.
|
||||||
|
@ -18,9 +18,9 @@ limitations under the License.
|
|||||||
|
|
||||||
package coverage
|
package coverage
|
||||||
|
|
||||||
// InitCoverage is a no-op when not running with coverage.
|
// InitCoverage is illegal when not running with coverage.
|
||||||
func InitCoverage(name string) {
|
func InitCoverage(name string) {
|
||||||
|
panic("Called InitCoverage when not built with coverage instrumentation.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlushCoverage is a no-op when not running with coverage.
|
// FlushCoverage is a no-op when not running with coverage.
|
||||||
|
Loading…
Reference in New Issue
Block a user