Skip to content

Commit

Permalink
Merge pull request AliyunContainerService#772 from miaogreat/feature/…
Browse files Browse the repository at this point in the history
…add_print

add event print when test failed
  • Loading branch information
l1b0k authored Jan 20, 2025
2 parents ef1ae15 + 09d3712 commit 3c04124
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,28 @@ func TestMain(m *testing.M) {
setPodNetworking,
)
testenv.AfterEachFeature(func(ctx context.Context, config *envconf.Config, t *testing.T, feature features.Feature) (context.Context, error) {
pod := &corev1.PodList{}
err = config.Client().Resources(envCfg.Namespace()).List(ctx, pod)
t.Log("---------list pods---------")
// 遍历 Pod 列表,筛选出非 Running 状态的 Pod
isTestFailed := false
for _, printPod := range pod.Items {
if printPod.Status.Phase != corev1.PodRunning {
isTestFailed = true
}
t.Logf("Pod: %s/%s, Node: %s, Status: %s\n", printPod.Namespace, printPod.Name, printPod.Spec.NodeName, printPod.Status.Phase)
}
if isTestFailed {
t.Log("---------list events---------")
// 遍历 Event 列表
event := &corev1.EventList{}
err = config.Client().Resources(envCfg.Namespace()).List(ctx, event)
for _, printEvent := range event.Items {
t.Logf("%s/%s, Event: %s %s, Time:%s\n", printEvent.InvolvedObject.Kind, printEvent.InvolvedObject.Name, printEvent.Reason, printEvent.Message, printEvent.LastTimestamp)
}
}
lo.ForEach(ResourcesFromCtx(ctx), func(item client.Object, index int) {
_ = config.Client().Resources().Delete(ctx, item)

err := wait.For(conditions.New(config.Client().Resources()).ResourceDeleted(item),
wait.WithInterval(1*time.Second), wait.WithImmediate(), wait.WithTimeout(1*time.Minute))
if err != nil {
Expand Down

0 comments on commit 3c04124

Please sign in to comment.