@@ -1538,6 +1538,81 @@ func TestFormatAttachedApps(t *testing.T) {
15381538 }
15391539}
15401540
1541+ // Test DeleteAttachment functionality
1542+ func TestDeleteAttachment (t * testing.T ) {
1543+ ctx := setupTestContext ()
1544+
1545+ clusterID := "test-cluster-123"
1546+
1547+ t .Run ("successful attachment deletion" , func (t * testing.T ) {
1548+ mockUiex := & mock.UiexClient {
1549+ DeleteAttachmentFunc : func (ctx context.Context , clusterId string , appName string ) (uiex.DeleteAttachmentResponse , error ) {
1550+ assert .Equal (t , clusterID , clusterId )
1551+ assert .Equal (t , "test-app" , appName )
1552+ return uiex.DeleteAttachmentResponse {
1553+ Data : struct {
1554+ Message string `json:"message"`
1555+ }{
1556+ Message : "Attachment deleted successfully" ,
1557+ },
1558+ }, nil
1559+ },
1560+ }
1561+
1562+ ctx := uiexutil .NewContextWithClient (ctx , mockUiex )
1563+
1564+ response , err := mockUiex .DeleteAttachment (ctx , clusterID , "test-app" )
1565+
1566+ require .NoError (t , err )
1567+ assert .Equal (t , "Attachment deleted successfully" , response .Data .Message )
1568+ })
1569+
1570+ t .Run ("error - attachment not found" , func (t * testing.T ) {
1571+ mockUiex := & mock.UiexClient {
1572+ DeleteAttachmentFunc : func (ctx context.Context , clusterId string , appName string ) (uiex.DeleteAttachmentResponse , error ) {
1573+ return uiex.DeleteAttachmentResponse {}, fmt .Errorf ("attachment not found for app '%s' on cluster %s" , appName , clusterId )
1574+ },
1575+ }
1576+
1577+ ctx := uiexutil .NewContextWithClient (ctx , mockUiex )
1578+
1579+ _ , err := mockUiex .DeleteAttachment (ctx , clusterID , "nonexistent-app" )
1580+
1581+ assert .Error (t , err )
1582+ assert .Contains (t , err .Error (), "attachment not found" )
1583+ })
1584+
1585+ t .Run ("error - access denied" , func (t * testing.T ) {
1586+ mockUiex := & mock.UiexClient {
1587+ DeleteAttachmentFunc : func (ctx context.Context , clusterId string , appName string ) (uiex.DeleteAttachmentResponse , error ) {
1588+ return uiex.DeleteAttachmentResponse {}, fmt .Errorf ("access denied: you don't have permission to detach from cluster %s" , clusterId )
1589+ },
1590+ }
1591+
1592+ ctx := uiexutil .NewContextWithClient (ctx , mockUiex )
1593+
1594+ _ , err := mockUiex .DeleteAttachment (ctx , clusterID , "test-app" )
1595+
1596+ assert .Error (t , err )
1597+ assert .Contains (t , err .Error (), "access denied" )
1598+ })
1599+
1600+ t .Run ("error - cluster not found" , func (t * testing.T ) {
1601+ mockUiex := & mock.UiexClient {
1602+ DeleteAttachmentFunc : func (ctx context.Context , clusterId string , appName string ) (uiex.DeleteAttachmentResponse , error ) {
1603+ return uiex.DeleteAttachmentResponse {}, fmt .Errorf ("cluster %s not found" , clusterId )
1604+ },
1605+ }
1606+
1607+ ctx := uiexutil .NewContextWithClient (ctx , mockUiex )
1608+
1609+ _ , err := mockUiex .DeleteAttachment (ctx , "nonexistent-cluster" , "test-app" )
1610+
1611+ assert .Error (t , err )
1612+ assert .Contains (t , err .Error (), "not found" )
1613+ })
1614+ }
1615+
15411616// Test the list command with attached apps
15421617func TestListCommand_WithAttachedApps (t * testing.T ) {
15431618 ctx := setupTestContext ()
0 commit comments