@@ -25,6 +25,7 @@ import type {
25
25
KubernetesProviderConnection ,
26
26
ProviderCleanup ,
27
27
ProviderInstallation ,
28
+ ProviderLifecycle ,
28
29
ProviderUpdate ,
29
30
} from '@podman-desktop/api' ;
30
31
import { beforeEach , describe , expect , test , vi } from 'vitest' ;
@@ -1000,3 +1001,99 @@ describe('runPreflightChecks', () => {
1000
1001
expect ( run ) . toBeFalsy ( ) ;
1001
1002
} ) ;
1002
1003
} ) ;
1004
+
1005
+ describe ( 'startProvider' , ( ) => {
1006
+ test ( 'if providerLifecycles is registered for the provider call startProviderLifecycle' , async ( ) => {
1007
+ const provider = providerRegistry . createProvider ( 'id' , 'name' , {
1008
+ id : 'internal' ,
1009
+ name : 'internal' ,
1010
+ status : 'installed' ,
1011
+ } ) ;
1012
+ const disposable = providerRegistry . registerLifecycle ( provider as ProviderImpl , { } as ProviderLifecycle ) ;
1013
+ const startProviderLifecycleMock = vi
1014
+ . spyOn ( providerRegistry , 'startProviderLifecycle' )
1015
+ . mockImplementation ( _id => Promise . resolve ( ) ) ;
1016
+ await providerRegistry . startProvider ( ( provider as ProviderImpl ) . internalId ) ;
1017
+ expect ( startProviderLifecycleMock ) . toBeCalledWith ( ( provider as ProviderImpl ) . internalId ) ;
1018
+ disposable . dispose ( ) ;
1019
+ } ) ;
1020
+
1021
+ test ( 'if the provider has no lifecycle and no connection, throw' , async ( ) => {
1022
+ const provider = providerRegistry . createProvider ( 'id' , 'name' , {
1023
+ id : 'internal' ,
1024
+ name : 'internal' ,
1025
+ status : 'installed' ,
1026
+ } ) ;
1027
+ await expect ( ( ) => providerRegistry . startProvider ( ( provider as ProviderImpl ) . internalId ) ) . rejects . toThrowError (
1028
+ 'The provider does not have any connection to start' ,
1029
+ ) ;
1030
+ } ) ;
1031
+
1032
+ test ( 'if the provider has one connection without the start lifecycle, throw' , async ( ) => {
1033
+ const provider = providerRegistry . createProvider ( 'id' , 'name' , {
1034
+ id : 'internal' ,
1035
+ name : 'internal' ,
1036
+ status : 'installed' ,
1037
+ } ) ;
1038
+ provider . registerContainerProviderConnection ( {
1039
+ name : 'connection' ,
1040
+ type : 'podman' ,
1041
+ endpoint : {
1042
+ socketPath : '/endpoint1.sock' ,
1043
+ } ,
1044
+ status ( ) {
1045
+ return 'stopped' ;
1046
+ } ,
1047
+ } ) ;
1048
+ await expect ( ( ) => providerRegistry . startProvider ( ( provider as ProviderImpl ) . internalId ) ) . rejects . toThrowError (
1049
+ 'The connection connection does not support start lifecycle' ,
1050
+ ) ;
1051
+ } ) ;
1052
+
1053
+ test ( 'if the provider has one container connection with the start lifecycle, execute the start action' , async ( ) => {
1054
+ const provider = providerRegistry . createProvider ( 'id' , 'name' , {
1055
+ id : 'internal' ,
1056
+ name : 'internal' ,
1057
+ status : 'installed' ,
1058
+ } ) ;
1059
+ const startMock = vi . fn ( ) ;
1060
+ provider . registerContainerProviderConnection ( {
1061
+ name : 'connection' ,
1062
+ type : 'podman' ,
1063
+ lifecycle : {
1064
+ start : startMock ,
1065
+ } ,
1066
+ endpoint : {
1067
+ socketPath : '/endpoint1.sock' ,
1068
+ } ,
1069
+ status ( ) {
1070
+ return 'stopped' ;
1071
+ } ,
1072
+ } ) ;
1073
+ await providerRegistry . startProvider ( ( provider as ProviderImpl ) . internalId ) ;
1074
+ expect ( startMock ) . toBeCalled ( ) ;
1075
+ } ) ;
1076
+
1077
+ test ( 'if the provider has one kubernetes connection with the start lifecycle, execute the start action' , async ( ) => {
1078
+ const provider = providerRegistry . createProvider ( 'id' , 'name' , {
1079
+ id : 'internal' ,
1080
+ name : 'internal' ,
1081
+ status : 'installed' ,
1082
+ } ) ;
1083
+ const startMock = vi . fn ( ) ;
1084
+ provider . registerKubernetesProviderConnection ( {
1085
+ name : 'connection' ,
1086
+ lifecycle : {
1087
+ start : startMock ,
1088
+ } ,
1089
+ endpoint : {
1090
+ apiURL : 'url' ,
1091
+ } ,
1092
+ status ( ) {
1093
+ return 'stopped' ;
1094
+ } ,
1095
+ } ) ;
1096
+ await providerRegistry . startProvider ( ( provider as ProviderImpl ) . internalId ) ;
1097
+ expect ( startMock ) . toBeCalled ( ) ;
1098
+ } ) ;
1099
+ } ) ;
0 commit comments