improve logging, fix expected filename for downloadonly

pull/5150/head
Medya Gh 2019-08-21 09:58:22 -07:00
parent c7e0d3aa8e
commit b3c9eea3d8
2 changed files with 11 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
@ -48,20 +49,23 @@ func TestDownloadOnly(t *testing.T) {
minHome := constants.GetMinipath()
for _, v := range []string{constants.OldestKubernetesVersion, constants.NewestKubernetesVersion} {
mk.StartWithFail("--download-only", fmt.Sprintf("--kubernetes-version=%s", v))
// checking if cached images are downloaded to
// checking if cached images are downloaded for example (kube-apiserver_v1.15.2, kube-scheduler_v1.15.2, ...)
_, imgs := constants.GetKubeadmCachedImages("", v)
for _, img := range imgs {
_, err := os.Stat(filepath.Join(minHome, fmt.Sprintf("images/%s", img)))
img = strings.Replace(img, ":", "_", 1) // for example kube-scheduler:v1.15.2 --> kube-scheduler_v1.15.2
fp := filepath.Join(minHome, "cache", "images", img)
_, err := os.Stat(fp)
if err != nil {
t.Errorf("error expected download-only to cachne image %q but got error %v", img, err)
t.Errorf("expected image file exist at %q but got error: %v", fp, err)
}
}
// checking binaries downloaded (kubelet,kubeadm)
for _, bin := range constants.GetKubeadmCachedBinaries() {
_, err := os.Stat(filepath.Join(minHome, fmt.Sprintf("cache/%s/%s", v, bin)))
fp := filepath.Join(minHome, "cache", v, bin)
_, err := os.Stat(fp)
if err != nil {
t.Errorf("error expected download-only to cachne binary %q but got error %v", bin, err)
t.Errorf("expected the file for binary exist at %q but got error %v", fp, err)
}
}
}

View File

@ -239,8 +239,9 @@ func (m *MinikubeRunner) start(opts ...string) (stdout string, stderr string, er
// StartWithFail starts the cluster and fail the test if error
func (m *MinikubeRunner) StartWithFail(opts ...string) (stdout string, stderr string) {
stdout, stderr, err := m.start(opts...)
// the reason for this formatting is, the logs are very big but useful and also in parallel testing logs are harder to identify
if err != nil {
m.T.Fatalf("%s Failed to start minikube (for profile %s) error: %v \n\twith opts %v, \n\t Global Args: %s \n\t Driver Args: %s \n\t STDOUT: \n\t\t %s \n\t STDERR: \n\t\t %s", m.T.Name(), m.Profile, err, strings.Join(opts, " "), m.GlobalArgs, m.StartArgs, stdout, stderr)
m.T.Fatalf("%s Failed to start minikube With error: %v \n\t Start log block ---> \n\t With Profile: %s \n\t With Args: %v \n\t With Global Args: %s \n\t With Driver Args: %s \n\t With STDOUT: \n \t %s \n\t With STDERR: \n \t %s \n\t <--- End of log block", m.T.Name(), err, m.Profile, strings.Join(opts, " "), m.GlobalArgs, m.StartArgs, stdout, stderr)
}
return stdout, stderr
}