@@ -958,3 +958,259 @@ func TestKubernetesTemplateAppConfig(t *testing.T) {
958958 assert .Equal (t , "APPLICATION NAME" , config .Groups [0 ].Items [0 ].Title )
959959 assert .Equal (t , "myapp" , config .Groups [0 ].Items [0 ].Value .StrVal )
960960}
961+
962+ func TestRunLinuxAppPreflights (t * testing.T ) {
963+ // Create a test server
964+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
965+ assert .Equal (t , "POST" , r .Method )
966+ assert .Equal (t , "/api/linux/install/app-preflights/run" , r .URL .Path )
967+
968+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
969+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
970+
971+ // Return successful response
972+ w .WriteHeader (http .StatusOK )
973+ json .NewEncoder (w ).Encode (types.InstallAppPreflightsStatusResponse {
974+ Status : types.Status {
975+ State : types .StateRunning ,
976+ Description : "App preflights running" ,
977+ },
978+ Output : & types.PreflightsOutput {
979+ Pass : []types.PreflightsRecord {
980+ {
981+ Title : "App Dependencies" ,
982+ Message : "All dependencies available" ,
983+ },
984+ },
985+ },
986+ Titles : []string {"App Dependencies" },
987+ })
988+ }))
989+ defer server .Close ()
990+
991+ // Test successful run
992+ c := New (server .URL , WithToken ("test-token" ))
993+ status , err := c .RunLinuxAppPreflights ()
994+ assert .NoError (t , err )
995+ assert .Equal (t , types .StateRunning , status .Status .State )
996+ assert .Equal (t , "App preflights running" , status .Status .Description )
997+ assert .Equal (t , "App Dependencies" , status .Output .Pass [0 ].Title )
998+ assert .Equal (t , "All dependencies available" , status .Output .Pass [0 ].Message )
999+ assert .Equal (t , []string {"App Dependencies" }, status .Titles )
1000+
1001+ // Test error response
1002+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1003+ w .WriteHeader (http .StatusConflict )
1004+ json .NewEncoder (w ).Encode (types.APIError {
1005+ StatusCode : http .StatusConflict ,
1006+ Message : "App preflights already running" ,
1007+ })
1008+ }))
1009+ defer errorServer .Close ()
1010+
1011+ c = New (errorServer .URL , WithToken ("test-token" ))
1012+ status , err = c .RunLinuxAppPreflights ()
1013+ assert .Error (t , err )
1014+ assert .Equal (t , types.InstallAppPreflightsStatusResponse {}, status )
1015+
1016+ apiErr , ok := err .(* types.APIError )
1017+ require .True (t , ok , "Expected err to be of type *types.APIError" )
1018+ assert .Equal (t , http .StatusConflict , apiErr .StatusCode )
1019+ assert .Equal (t , "App preflights already running" , apiErr .Message )
1020+ }
1021+
1022+ func TestGetLinuxAppPreflightsStatus (t * testing.T ) {
1023+ // Create a test server
1024+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1025+ assert .Equal (t , "GET" , r .Method )
1026+ assert .Equal (t , "/api/linux/install/app-preflights/status" , r .URL .Path )
1027+
1028+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
1029+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1030+
1031+ // Return successful response
1032+ w .WriteHeader (http .StatusOK )
1033+ json .NewEncoder (w ).Encode (types.InstallAppPreflightsStatusResponse {
1034+ Status : types.Status {
1035+ State : types .StateSucceeded ,
1036+ Description : "App preflights succeeded" ,
1037+ },
1038+ Output : & types.PreflightsOutput {
1039+ Pass : []types.PreflightsRecord {
1040+ {
1041+ Title : "Storage Check" ,
1042+ Message : "Sufficient storage available" ,
1043+ },
1044+ },
1045+ Fail : []types.PreflightsRecord {
1046+ {
1047+ Title : "Network Check" ,
1048+ Message : "Network connectivity issues" ,
1049+ },
1050+ },
1051+ },
1052+ Titles : []string {"Storage Check" , "Network Check" },
1053+ })
1054+ }))
1055+ defer server .Close ()
1056+
1057+ // Test successful get
1058+ c := New (server .URL , WithToken ("test-token" ))
1059+ status , err := c .GetLinuxAppPreflightsStatus ()
1060+ assert .NoError (t , err )
1061+ assert .Equal (t , types .StateSucceeded , status .Status .State )
1062+ assert .Equal (t , "App preflights succeeded" , status .Status .Description )
1063+ assert .Equal (t , "Storage Check" , status .Output .Pass [0 ].Title )
1064+ assert .Equal (t , "Sufficient storage available" , status .Output .Pass [0 ].Message )
1065+ assert .Equal (t , "Network Check" , status .Output .Fail [0 ].Title )
1066+ assert .Equal (t , "Network connectivity issues" , status .Output .Fail [0 ].Message )
1067+ assert .Equal (t , []string {"Storage Check" , "Network Check" }, status .Titles )
1068+
1069+ // Test error response
1070+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1071+ w .WriteHeader (http .StatusInternalServerError )
1072+ json .NewEncoder (w ).Encode (types.APIError {
1073+ StatusCode : http .StatusInternalServerError ,
1074+ Message : "Internal Server Error" ,
1075+ })
1076+ }))
1077+ defer errorServer .Close ()
1078+
1079+ c = New (errorServer .URL , WithToken ("test-token" ))
1080+ status , err = c .GetLinuxAppPreflightsStatus ()
1081+ assert .Error (t , err )
1082+ assert .Equal (t , types.InstallAppPreflightsStatusResponse {}, status )
1083+
1084+ apiErr , ok := err .(* types.APIError )
1085+ require .True (t , ok , "Expected err to be of type *types.APIError" )
1086+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1087+ assert .Equal (t , "Internal Server Error" , apiErr .Message )
1088+ }
1089+
1090+ func TestRunKubernetesAppPreflights (t * testing.T ) {
1091+ // Create a test server
1092+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1093+ assert .Equal (t , "POST" , r .Method )
1094+ assert .Equal (t , "/api/kubernetes/install/app-preflights/run" , r .URL .Path )
1095+
1096+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
1097+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1098+
1099+ // Return successful response
1100+ w .WriteHeader (http .StatusOK )
1101+ json .NewEncoder (w ).Encode (types.InstallAppPreflightsStatusResponse {
1102+ Status : types.Status {
1103+ State : types .StateRunning ,
1104+ Description : "App preflights running on Kubernetes" ,
1105+ },
1106+ Output : & types.PreflightsOutput {
1107+ Pass : []types.PreflightsRecord {
1108+ {
1109+ Title : "Cluster Resources" ,
1110+ Message : "Sufficient cluster resources" ,
1111+ },
1112+ },
1113+ },
1114+ Titles : []string {"Cluster Resources" },
1115+ })
1116+ }))
1117+ defer server .Close ()
1118+
1119+ // Test successful run
1120+ c := New (server .URL , WithToken ("test-token" ))
1121+ status , err := c .RunKubernetesAppPreflights ()
1122+ assert .NoError (t , err )
1123+ assert .Equal (t , types .StateRunning , status .Status .State )
1124+ assert .Equal (t , "App preflights running on Kubernetes" , status .Status .Description )
1125+ assert .Equal (t , "Cluster Resources" , status .Output .Pass [0 ].Title )
1126+ assert .Equal (t , "Sufficient cluster resources" , status .Output .Pass [0 ].Message )
1127+ assert .Equal (t , []string {"Cluster Resources" }, status .Titles )
1128+
1129+ // Test error response
1130+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1131+ w .WriteHeader (http .StatusConflict )
1132+ json .NewEncoder (w ).Encode (types.APIError {
1133+ StatusCode : http .StatusConflict ,
1134+ Message : "App preflights already running" ,
1135+ })
1136+ }))
1137+ defer errorServer .Close ()
1138+
1139+ c = New (errorServer .URL , WithToken ("test-token" ))
1140+ status , err = c .RunKubernetesAppPreflights ()
1141+ assert .Error (t , err )
1142+ assert .Equal (t , types.InstallAppPreflightsStatusResponse {}, status )
1143+
1144+ apiErr , ok := err .(* types.APIError )
1145+ require .True (t , ok , "Expected err to be of type *types.APIError" )
1146+ assert .Equal (t , http .StatusConflict , apiErr .StatusCode )
1147+ assert .Equal (t , "App preflights already running" , apiErr .Message )
1148+ }
1149+
1150+ func TestGetKubernetesAppPreflightsStatus (t * testing.T ) {
1151+ // Create a test server
1152+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1153+ assert .Equal (t , "GET" , r .Method )
1154+ assert .Equal (t , "/api/kubernetes/install/app-preflights/status" , r .URL .Path )
1155+
1156+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
1157+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1158+
1159+ // Return successful response
1160+ w .WriteHeader (http .StatusOK )
1161+ json .NewEncoder (w ).Encode (types.InstallAppPreflightsStatusResponse {
1162+ Status : types.Status {
1163+ State : types .StateFailed ,
1164+ Description : "App preflights failed on Kubernetes" ,
1165+ },
1166+ Output : & types.PreflightsOutput {
1167+ Pass : []types.PreflightsRecord {
1168+ {
1169+ Title : "RBAC Check" ,
1170+ Message : "Sufficient permissions" ,
1171+ },
1172+ },
1173+ Fail : []types.PreflightsRecord {
1174+ {
1175+ Title : "Storage Class" ,
1176+ Message : "No default storage class found" ,
1177+ },
1178+ },
1179+ },
1180+ Titles : []string {"RBAC Check" , "Storage Class" },
1181+ })
1182+ }))
1183+ defer server .Close ()
1184+
1185+ // Test successful get
1186+ c := New (server .URL , WithToken ("test-token" ))
1187+ status , err := c .GetKubernetesAppPreflightsStatus ()
1188+ assert .NoError (t , err )
1189+ assert .Equal (t , types .StateFailed , status .Status .State )
1190+ assert .Equal (t , "App preflights failed on Kubernetes" , status .Status .Description )
1191+ assert .Equal (t , "RBAC Check" , status .Output .Pass [0 ].Title )
1192+ assert .Equal (t , "Sufficient permissions" , status .Output .Pass [0 ].Message )
1193+ assert .Equal (t , "Storage Class" , status .Output .Fail [0 ].Title )
1194+ assert .Equal (t , "No default storage class found" , status .Output .Fail [0 ].Message )
1195+ assert .Equal (t , []string {"RBAC Check" , "Storage Class" }, status .Titles )
1196+
1197+ // Test error response
1198+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1199+ w .WriteHeader (http .StatusInternalServerError )
1200+ json .NewEncoder (w ).Encode (types.APIError {
1201+ StatusCode : http .StatusInternalServerError ,
1202+ Message : "Internal Server Error" ,
1203+ })
1204+ }))
1205+ defer errorServer .Close ()
1206+
1207+ c = New (errorServer .URL , WithToken ("test-token" ))
1208+ status , err = c .GetKubernetesAppPreflightsStatus ()
1209+ assert .Error (t , err )
1210+ assert .Equal (t , types.InstallAppPreflightsStatusResponse {}, status )
1211+
1212+ apiErr , ok := err .(* types.APIError )
1213+ require .True (t , ok , "Expected err to be of type *types.APIError" )
1214+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1215+ assert .Equal (t , "Internal Server Error" , apiErr .Message )
1216+ }
0 commit comments