@@ -802,6 +802,65 @@ func TestCommonControl_buildClaimOptions(t *testing.T) {
802802 }
803803 },
804804 },
805+ {
806+ name : "claim with pauseTime" ,
807+ claim : & agentsv1alpha1.SandboxClaim {
808+ ObjectMeta : metav1.ObjectMeta {
809+ Name : "test-claim" ,
810+ Namespace : "default" ,
811+ UID : "test-uid-pause" ,
812+ },
813+ Spec : agentsv1alpha1.SandboxClaimSpec {
814+ TemplateName : "test-template" ,
815+ PauseTime : & shutdownTime ,
816+ },
817+ },
818+ sandboxSet : & agentsv1alpha1.SandboxSet {
819+ ObjectMeta : metav1.ObjectMeta {
820+ Name : "test-template" ,
821+ Namespace : "default" ,
822+ },
823+ },
824+ expectError : false ,
825+ validate : func (t * testing.T , opts infra.ClaimSandboxOptions ) {
826+ if opts .User != "test-uid-pause" {
827+ t .Errorf ("User = %v, want %v" , opts .User , "test-uid-pause" )
828+ }
829+ if opts .Modifier == nil {
830+ t .Error ("Modifier should not be nil" )
831+ }
832+ },
833+ },
834+ {
835+ name : "claim with both shutdownTime and pauseTime" ,
836+ claim : & agentsv1alpha1.SandboxClaim {
837+ ObjectMeta : metav1.ObjectMeta {
838+ Name : "test-claim" ,
839+ Namespace : "default" ,
840+ UID : "test-uid-both-times" ,
841+ },
842+ Spec : agentsv1alpha1.SandboxClaimSpec {
843+ TemplateName : "test-template" ,
844+ ShutdownTime : & shutdownTime ,
845+ PauseTime : & shutdownTime ,
846+ },
847+ },
848+ sandboxSet : & agentsv1alpha1.SandboxSet {
849+ ObjectMeta : metav1.ObjectMeta {
850+ Name : "test-template" ,
851+ Namespace : "default" ,
852+ },
853+ },
854+ expectError : false ,
855+ validate : func (t * testing.T , opts infra.ClaimSandboxOptions ) {
856+ if opts .User != "test-uid-both-times" {
857+ t .Errorf ("User = %v, want %v" , opts .User , "test-uid-both-times" )
858+ }
859+ if opts .Modifier == nil {
860+ t .Error ("Modifier should not be nil" )
861+ }
862+ },
863+ },
805864 {
806865 name : "claim with inplaceUpdate - image only" ,
807866 claim : & agentsv1alpha1.SandboxClaim {
@@ -1119,6 +1178,121 @@ func TestCommonControl_buildClaimOptions_Modifier(t *testing.T) {
11191178 t .Errorf ("Expected custom-annotation = %v, got %v" ,
11201179 "value2" , mockSandbox .Annotations ["custom-annotation" ])
11211180 }
1181+
1182+ // Verify shutdownTime was set correctly on the sandbox
1183+ if mockSandbox .Sandbox .Spec .ShutdownTime == nil {
1184+ t .Fatal ("Expected ShutdownTime to be set on sandbox" )
1185+ }
1186+ if ! mockSandbox .Sandbox .Spec .ShutdownTime .Time .Equal (shutdownTime .Time ) {
1187+ t .Errorf ("Expected ShutdownTime = %v, got %v" , shutdownTime .Time , mockSandbox .Sandbox .Spec .ShutdownTime .Time )
1188+ }
1189+ }
1190+
1191+ // TestCommonControl_buildClaimOptions_TimeoutModifier tests that shutdownTime and pauseTime
1192+ // are correctly applied to the sandbox via the modifier.
1193+ func TestCommonControl_buildClaimOptions_TimeoutModifier (t * testing.T ) {
1194+ scheme := runtime .NewScheme ()
1195+ _ = agentsv1alpha1 .AddToScheme (scheme )
1196+
1197+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
1198+ fakeRecorder := record .NewFakeRecorder (10 )
1199+ control := NewCommonControl (fakeClient , fakeRecorder , nil , nil ).(* commonControl )
1200+ ctx := context .Background ()
1201+
1202+ now := metav1 .Now ()
1203+ pauseTime := metav1 .NewTime (now .Add (10 * time .Minute ))
1204+ shutdownTime := metav1 .NewTime (now .Add (30 * time .Minute ))
1205+
1206+ tests := []struct {
1207+ name string
1208+ shutdownTime * metav1.Time
1209+ pauseTime * metav1.Time
1210+ wantShutdownTime * metav1.Time
1211+ wantPauseTime * metav1.Time
1212+ }{
1213+ {
1214+ name : "only shutdownTime" ,
1215+ shutdownTime : & shutdownTime ,
1216+ wantShutdownTime : & shutdownTime ,
1217+ wantPauseTime : nil ,
1218+ },
1219+ {
1220+ name : "only pauseTime" ,
1221+ pauseTime : & pauseTime ,
1222+ wantPauseTime : & pauseTime ,
1223+ wantShutdownTime : nil ,
1224+ },
1225+ {
1226+ name : "both shutdownTime and pauseTime" ,
1227+ shutdownTime : & shutdownTime ,
1228+ pauseTime : & pauseTime ,
1229+ wantShutdownTime : & shutdownTime ,
1230+ wantPauseTime : & pauseTime ,
1231+ },
1232+ {
1233+ name : "neither shutdownTime nor pauseTime" ,
1234+ wantShutdownTime : nil ,
1235+ wantPauseTime : nil ,
1236+ },
1237+ }
1238+
1239+ for _ , tt := range tests {
1240+ t .Run (tt .name , func (t * testing.T ) {
1241+ claim := & agentsv1alpha1.SandboxClaim {
1242+ ObjectMeta : metav1.ObjectMeta {
1243+ Name : "test-claim" ,
1244+ Namespace : "default" ,
1245+ UID : "test-uid" ,
1246+ },
1247+ Spec : agentsv1alpha1.SandboxClaimSpec {
1248+ TemplateName : "test-template" ,
1249+ ShutdownTime : tt .shutdownTime ,
1250+ PauseTime : tt .pauseTime ,
1251+ },
1252+ }
1253+ sandboxSet := & agentsv1alpha1.SandboxSet {
1254+ ObjectMeta : metav1.ObjectMeta {Name : "test-template" , Namespace : "default" },
1255+ }
1256+
1257+ opts , err := control .buildClaimOptions (ctx , claim , sandboxSet )
1258+ if err != nil {
1259+ t .Fatalf ("buildClaimOptions() error = %v" , err )
1260+ }
1261+
1262+ mockSandbox := & sandboxcr.Sandbox {
1263+ Sandbox : & agentsv1alpha1.Sandbox {
1264+ ObjectMeta : metav1.ObjectMeta {Name : "test-sandbox" , Namespace : "default" },
1265+ },
1266+ }
1267+ opts .Modifier (mockSandbox )
1268+
1269+ if tt .wantShutdownTime == nil {
1270+ if mockSandbox .Sandbox .Spec .ShutdownTime != nil {
1271+ t .Errorf ("expected ShutdownTime to be nil, got %v" , mockSandbox .Sandbox .Spec .ShutdownTime )
1272+ }
1273+ } else {
1274+ if mockSandbox .Sandbox .Spec .ShutdownTime == nil {
1275+ t .Fatal ("expected ShutdownTime to be set, got nil" )
1276+ }
1277+ if ! mockSandbox .Sandbox .Spec .ShutdownTime .Time .Equal (tt .wantShutdownTime .Time ) {
1278+ t .Errorf ("ShutdownTime = %v, want %v" , mockSandbox .Sandbox .Spec .ShutdownTime .Time , tt .wantShutdownTime .Time )
1279+ }
1280+ }
1281+
1282+ if tt .wantPauseTime == nil {
1283+ if mockSandbox .Sandbox .Spec .PauseTime != nil {
1284+ t .Errorf ("expected PauseTime to be nil, got %v" , mockSandbox .Sandbox .Spec .PauseTime )
1285+ }
1286+ } else {
1287+ if mockSandbox .Sandbox .Spec .PauseTime == nil {
1288+ t .Fatal ("expected PauseTime to be set, got nil" )
1289+ }
1290+ if ! mockSandbox .Sandbox .Spec .PauseTime .Time .Equal (tt .wantPauseTime .Time ) {
1291+ t .Errorf ("PauseTime = %v, want %v" , mockSandbox .Sandbox .Spec .PauseTime .Time , tt .wantPauseTime .Time )
1292+ }
1293+ }
1294+ })
1295+ }
11221296}
11231297
11241298// Helper function for tests
0 commit comments