github.com/verrazzano/verrazzano@v1.7.0/tools/vz/pkg/analysis/internal/util/cluster/pods_test.go (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package cluster 4 5 import ( 6 "github.com/stretchr/testify/assert" 7 "github.com/verrazzano/verrazzano/tools/vz/pkg/analysis/internal/util/log" 8 corev1 "k8s.io/api/core/v1" 9 "testing" 10 ) 11 12 // TODO: Add more tests 13 14 func TestPodConditionMessage(t *testing.T) { 15 ns := "test" 16 var tests = []struct { 17 name string 18 condition corev1.PodCondition 19 message string 20 }{ 21 { 22 "pod-no-message-nor-reason", 23 corev1.PodCondition{ 24 Type: corev1.PodInitialized, 25 Status: corev1.ConditionFalse, 26 }, 27 "Namespace test, Pod pod-no-message-nor-reason, ConditionType Initialized, Status False", 28 }, 29 { 30 "pod-with-message-and-reason", 31 corev1.PodCondition{ 32 Type: corev1.ContainersReady, 33 Status: corev1.ConditionTrue, 34 Message: "foo", 35 Reason: "bar", 36 }, 37 "Namespace test, Pod pod-with-message-and-reason, ConditionType ContainersReady, Status True, Reason bar, Message foo", 38 }, 39 } 40 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 msg, err := podConditionMessage(tt.name, ns, tt.condition) 44 assert.NoError(t, err) 45 assert.Equal(t, tt.message, msg) 46 }) 47 } 48 } 49 50 // Analyze Pod Issues with variety of cluster roots 51 // Expect No Error for each analysis 52 func TestAnalyzePodIssues(t *testing.T) { 53 logger := log.GetDebugEnabledLogger() 54 assert.NoError(t, AnalyzePodIssues(logger, "../../../test/cluster/problem-pods/cluster-snapshot")) 55 assert.NoError(t, AnalyzePodIssues(logger, "../../../test/cluster/pending-pods/cluster-snapshot")) 56 assert.NoError(t, AnalyzePodIssues(logger, "../../../test/cluster/problem-pods-install/cluster-snapshot")) 57 assert.NoError(t, AnalyzePodIssues(logger, "../../../test/cluster/insufficient-mem/cluster-snapshot")) 58 }