package k8s_exec import ( "agent-go/utils" "fmt" "github.com/magiconair/properties/assert" "testing" "time" ) func TestFindAppNotHealthyOrRestartCountGreaterThanN(t *testing.T) { deploymentRestartCountGreaterThanN := FindAppNotHealthyOrRestartCountGreaterThanN("devflight", 10) deploymentRestartCountGreaterThanN = FilterAllCmiiAppSoft(deploymentRestartCountGreaterThanN) for _, deploymentInterface := range deploymentRestartCountGreaterThanN { println() utils.BeautifulPrint(deploymentInterface) println() } } func TestFindDeploymentReplicasSmallerThanN(t *testing.T) { deploymentReplicasSmallerThanN := FindDeploymentReplicasSmallerThanN("devflight", 0) for _, deploymentInterface := range deploymentReplicasSmallerThanN { println() utils.BeautifulPrint(deploymentInterface) println() } } func TestGetCmiiAllDeploymentFromEnv(t *testing.T) { BackupAllDeploymentFromEnv("uavms") } func TestBackupAllCmiiDeploymentToMap(t *testing.T) { backendMap, frontendMap := BackupAllCmiiDeploymentToMap("demo") utils.BeautifulPrint(backendMap) utils.BeautifulPrint(frontendMap) } func TestUpdateCmiiDeploymentImageTag(t *testing.T) { cmiiEnv := "uavms" appName := "uavms-lowaltitude-platform" newTag := "5.2.0-011202" tag := UpdateCmiiDeploymentImageTag(cmiiEnv, appName, newTag) assert.Equal(t, tag, true, "update image tag failed !") check := CmiiOperator.DeploymentStatusCheck(cmiiEnv, appName, 180) assert.Equal(t, check, true, "deployment run failed!") } func TestRollBackCmiiDeploymentFromUpdateLog(t *testing.T) { updateLog := RollBackCmiiDeploymentFromUpdateLog("2024-01-10-14-37-07 uavcloud-devflight cmii-uav-depotautoreturn 12345678 123sdsa45678") assert.Equal(t, updateLog, true, "roll back from update log failed !") } func TestRestartCmiiBackendDeployment(t *testing.T) { RestartCmiiBackendDeployment("test") } func TestRestartCmiiFrontendDeployment(t *testing.T) { RestartCmiiFrontendDeployment("devflight") } func TestFindDeploymentNotHealthy(t *testing.T) { notHealthy := FindDeploymentNotHealthy("devflight") notHealthy = FilterAllCmiiAppSoft(notHealthy) for _, deploymentInterface := range notHealthy { utils.BeautifulPrint(deploymentInterface) } } func TestFindAllNodeNotHealthy(t *testing.T) { start := time.Now() allNodeNotHealthy := FindAllNodeNotHealthy() elapsed := time.Since(start).Milliseconds() fmt.Printf("执行耗时: %d ms\n", elapsed) for _, nodeInterface := range allNodeNotHealthy { println() utils.BeautifulPrint(nodeInterface) println() } } func TestFindPodNotHealthy(t *testing.T) { podNotHealthy := FindPodNotHealthy("valida") podNotHealthy = FilterAllCmiiPodSoft(podNotHealthy) for _, podInterface := range podNotHealthy { t.Logf("[%s] [%s]", podInterface.Name, podInterface.PodPhase) } } func TestFindPodNotHealthy_And_Delete(t *testing.T) { podNotHealthy := FindPodNotHealthy("uavms") podNotHealthy = FilterAllCmiiPodSoft(podNotHealthy) for _, podInterface := range podNotHealthy { t.Logf("[%s] [%s]", podInterface.Name, podInterface.PodPhase) podDelete := CmiiOperator.PodDelete(podInterface.Namespace, podInterface.Name) assert.Equal(t, podDelete, true, "delete of ", podInterface.Namespace, podInterface.Name, " failed !") } } func TestFilterAllCmiiAppStrict(t *testing.T) { allInterface := CmiiOperator.DeploymentAllInterface("devflight") FilterAllCmiiAppStrict(allInterface) } func TestRestartDeploymentFromList(t *testing.T) { allInterface := CmiiOperator.DeploymentAllInterface("devflight") allInterface = FilterAllCmiiAppSoft(allInterface) RestartDeploymentFromList(allInterface) }