@@ -1214,3 +1214,181 @@ func TestGetKubernetesAppPreflightsStatus(t *testing.T) {
12141214 assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
12151215 assert .Equal (t , "Internal Server Error" , apiErr .Message )
12161216}
1217+
1218+ func TestClient_InstallLinuxApp (t * testing.T ) {
1219+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1220+ assert .Equal (t , "POST" , r .Method )
1221+ assert .Equal (t , "/api/linux/install/app/install" , r .URL .Path )
1222+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1223+
1224+ appInstall := types.AppInstall {
1225+ Status : types.Status {State : types .StateRunning , Description : "Installing app" },
1226+ Logs : "Installation started\n " ,
1227+ }
1228+ w .Header ().Set ("Content-Type" , "application/json" )
1229+ json .NewEncoder (w ).Encode (appInstall )
1230+ }))
1231+ defer server .Close ()
1232+
1233+ c := New (server .URL , WithToken ("test-token" ))
1234+ appInstall , err := c .InstallLinuxApp ()
1235+
1236+ require .NoError (t , err )
1237+ assert .Equal (t , types .StateRunning , appInstall .Status .State )
1238+ assert .Equal (t , "Installing app" , appInstall .Status .Description )
1239+ assert .Equal (t , "Installation started\n " , appInstall .Logs )
1240+ }
1241+
1242+ func TestClient_GetLinuxAppInstallStatus (t * testing.T ) {
1243+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1244+ assert .Equal (t , "GET" , r .Method )
1245+ assert .Equal (t , "/api/linux/install/app/status" , r .URL .Path )
1246+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1247+
1248+ appInstall := types.AppInstall {
1249+ Status : types.Status {State : types .StateSucceeded , Description : "App installed successfully" },
1250+ Logs : "Installation completed\n " ,
1251+ }
1252+ w .Header ().Set ("Content-Type" , "application/json" )
1253+ json .NewEncoder (w ).Encode (appInstall )
1254+ }))
1255+ defer server .Close ()
1256+
1257+ c := New (server .URL , WithToken ("test-token" ))
1258+ appInstall , err := c .GetLinuxAppInstallStatus ()
1259+
1260+ require .NoError (t , err )
1261+ assert .Equal (t , types .StateSucceeded , appInstall .Status .State )
1262+ assert .Equal (t , "App installed successfully" , appInstall .Status .Description )
1263+ assert .Equal (t , "Installation completed\n " , appInstall .Logs )
1264+ }
1265+
1266+ func TestClient_InstallKubernetesApp (t * testing.T ) {
1267+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1268+ assert .Equal (t , "POST" , r .Method )
1269+ assert .Equal (t , "/api/kubernetes/install/app/install" , r .URL .Path )
1270+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1271+
1272+ appInstall := types.AppInstall {
1273+ Status : types.Status {State : types .StateRunning , Description : "Installing app" },
1274+ Logs : "Kubernetes app installation started\n " ,
1275+ }
1276+ w .Header ().Set ("Content-Type" , "application/json" )
1277+ json .NewEncoder (w ).Encode (appInstall )
1278+ }))
1279+ defer server .Close ()
1280+
1281+ c := New (server .URL , WithToken ("test-token" ))
1282+ appInstall , err := c .InstallKubernetesApp ()
1283+
1284+ require .NoError (t , err )
1285+ assert .Equal (t , types .StateRunning , appInstall .Status .State )
1286+ assert .Equal (t , "Installing app" , appInstall .Status .Description )
1287+ assert .Equal (t , "Kubernetes app installation started\n " , appInstall .Logs )
1288+ }
1289+
1290+ func TestClient_GetKubernetesAppInstallStatus (t * testing.T ) {
1291+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1292+ assert .Equal (t , "GET" , r .Method )
1293+ assert .Equal (t , "/api/kubernetes/install/app/status" , r .URL .Path )
1294+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
1295+
1296+ appInstall := types.AppInstall {
1297+ Status : types.Status {State : types .StateFailed , Description : "App installation failed" },
1298+ Logs : "Installation failed with error\n " ,
1299+ }
1300+ w .Header ().Set ("Content-Type" , "application/json" )
1301+ json .NewEncoder (w ).Encode (appInstall )
1302+ }))
1303+ defer server .Close ()
1304+
1305+ c := New (server .URL , WithToken ("test-token" ))
1306+ appInstall , err := c .GetKubernetesAppInstallStatus ()
1307+
1308+ require .NoError (t , err )
1309+ assert .Equal (t , types .StateFailed , appInstall .Status .State )
1310+ assert .Equal (t , "App installation failed" , appInstall .Status .Description )
1311+ assert .Equal (t , "Installation failed with error\n " , appInstall .Logs )
1312+ }
1313+
1314+ func TestClient_AppInstallErrorHandling (t * testing.T ) {
1315+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1316+ apiError := types.APIError {
1317+ StatusCode : http .StatusInternalServerError ,
1318+ Message : "Internal server error" ,
1319+ }
1320+ w .Header ().Set ("Content-Type" , "application/json" )
1321+ w .WriteHeader (http .StatusInternalServerError )
1322+ json .NewEncoder (w ).Encode (apiError )
1323+ }))
1324+ defer server .Close ()
1325+
1326+ c := New (server .URL , WithToken ("test-token" ))
1327+
1328+ t .Run ("InstallLinuxApp error" , func (t * testing.T ) {
1329+ _ , err := c .InstallLinuxApp ()
1330+ require .Error (t , err )
1331+ apiErr , ok := err .(* types.APIError )
1332+ require .True (t , ok )
1333+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1334+ assert .Equal (t , "Internal server error" , apiErr .Message )
1335+ })
1336+
1337+ t .Run ("GetLinuxAppInstallStatus error" , func (t * testing.T ) {
1338+ _ , err := c .GetLinuxAppInstallStatus ()
1339+ require .Error (t , err )
1340+ apiErr , ok := err .(* types.APIError )
1341+ require .True (t , ok )
1342+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1343+ })
1344+
1345+ t .Run ("InstallKubernetesApp error" , func (t * testing.T ) {
1346+ _ , err := c .InstallKubernetesApp ()
1347+ require .Error (t , err )
1348+ apiErr , ok := err .(* types.APIError )
1349+ require .True (t , ok )
1350+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1351+ })
1352+
1353+ t .Run ("GetKubernetesAppInstallStatus error" , func (t * testing.T ) {
1354+ _ , err := c .GetKubernetesAppInstallStatus ()
1355+ require .Error (t , err )
1356+ apiErr , ok := err .(* types.APIError )
1357+ require .True (t , ok )
1358+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
1359+ })
1360+ }
1361+
1362+ func TestClient_AppInstallWithoutToken (t * testing.T ) {
1363+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1364+ // Verify no auth header is sent
1365+ assert .Empty (t , r .Header .Get ("Authorization" ))
1366+
1367+ apiError := types.APIError {
1368+ StatusCode : http .StatusUnauthorized ,
1369+ Message : "Unauthorized" ,
1370+ }
1371+ w .Header ().Set ("Content-Type" , "application/json" )
1372+ w .WriteHeader (http .StatusUnauthorized )
1373+ json .NewEncoder (w ).Encode (apiError )
1374+ }))
1375+ defer server .Close ()
1376+
1377+ c := New (server .URL ) // No token provided
1378+
1379+ t .Run ("InstallLinuxApp without token" , func (t * testing.T ) {
1380+ _ , err := c .InstallLinuxApp ()
1381+ require .Error (t , err )
1382+ apiErr , ok := err .(* types.APIError )
1383+ require .True (t , ok )
1384+ assert .Equal (t , http .StatusUnauthorized , apiErr .StatusCode )
1385+ })
1386+
1387+ t .Run ("GetLinuxAppInstallStatus without token" , func (t * testing.T ) {
1388+ _ , err := c .GetLinuxAppInstallStatus ()
1389+ require .Error (t , err )
1390+ apiErr , ok := err .(* types.APIError )
1391+ require .True (t , ok )
1392+ assert .Equal (t , http .StatusUnauthorized , apiErr .StatusCode )
1393+ })
1394+ }
0 commit comments