feat: seperate close function into tiny helper function

This commit is contained in:
2026-07-12 01:20:22 +07:00
parent efbff0f7f7
commit 0a5f673c68
5 changed files with 67 additions and 35 deletions
+11 -4
View File
@@ -177,8 +177,14 @@ func TestLifecycle_SetChannel(t *testing.T) {
mockSSHChannel := &MockSSHChannel{}
mockLifecycle.SetChannel(mockSSHChannel)
err := mockLifecycle.SetChannel(mockSSHChannel)
assert.NoError(t, err)
assert.Equal(t, mockSSHChannel, mockLifecycle.Channel())
anotherChannel := &MockSSHChannel{}
err = mockLifecycle.SetChannel(anotherChannel)
assert.Error(t, err)
assert.Contains(t, err.Error(), "channel already set")
assert.Equal(t, mockSSHChannel, mockLifecycle.Channel())
}
@@ -276,14 +282,15 @@ func TestLifecycle_Close(t *testing.T) {
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
mockLifecycle.SetChannel(mockSSHChannel)
err := mockLifecycle.SetChannel(mockSSHChannel)
assert.NoError(t, err)
if tt.alreadyClosed {
err := mockLifecycle.Close()
err = mockLifecycle.Close()
assert.NoError(t, err)
}
err := mockLifecycle.Close()
err = mockLifecycle.Close()
if tt.expectErr {
assert.Error(t, err)