mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
|
)
|
|
|
|
func TestValidateRayClusterStatus(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
conditions []metav1.Condition
|
|
expectError bool
|
|
}{
|
|
{
|
|
name: "Both suspending and suspended are true",
|
|
conditions: []metav1.Condition{
|
|
{
|
|
Type: string(rayv1.RayClusterSuspending),
|
|
Status: metav1.ConditionTrue,
|
|
},
|
|
{
|
|
Type: string(rayv1.RayClusterSuspended),
|
|
Status: metav1.ConditionTrue,
|
|
},
|
|
},
|
|
expectError: true,
|
|
},
|
|
{
|
|
name: "Only suspending is true",
|
|
conditions: []metav1.Condition{
|
|
{
|
|
Type: string(rayv1.RayClusterSuspending),
|
|
Status: metav1.ConditionTrue,
|
|
},
|
|
{
|
|
Type: string(rayv1.RayClusterSuspended),
|
|
Status: metav1.ConditionFalse,
|
|
},
|
|
},
|
|
expectError: false,
|
|
},
|
|
{
|
|
name: "Only suspended is true",
|
|
conditions: []metav1.Condition{
|
|
{
|
|
Type: string(rayv1.RayClusterSuspending),
|
|
Status: metav1.ConditionFalse,
|
|
},
|
|
{
|
|
Type: string(rayv1.RayClusterSuspended),
|
|
Status: metav1.ConditionTrue,
|
|
},
|
|
},
|
|
expectError: false,
|
|
},
|
|
{
|
|
name: "Both suspending and suspended are false",
|
|
conditions: []metav1.Condition{
|
|
{
|
|
Type: string(rayv1.RayClusterSuspending),
|
|
Status: metav1.ConditionFalse,
|
|
},
|
|
{
|
|
Type: string(rayv1.RayClusterSuspended),
|
|
Status: metav1.ConditionFalse,
|
|
},
|
|
},
|
|
expectError: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
instance := &rayv1.RayCluster{
|
|
Status: rayv1.RayClusterStatus{
|
|
Conditions: tt.conditions,
|
|
},
|
|
}
|
|
err := ValidateRayClusterStatus(instance)
|
|
if (err != nil) != tt.expectError {
|
|
t.Errorf("ValidateRayClusterStatus() error = %v, wantErr %v", err, tt.expectError)
|
|
}
|
|
})
|
|
}
|
|
}
|