TestRemoveSSHHostEntryFirstEntry verifies that the removeSSHHostEntry function correctly handles removal of the first entry in the SSH config file.
(t *testing.T)
| 89 | // TestRemoveSSHHostEntryFirstEntry verifies that the removeSSHHostEntry function |
| 90 | // correctly handles removal of the first entry in the SSH config file. |
| 91 | func TestRemoveSSHHostEntryFirstEntry(t *testing.T) { |
| 92 | env := testutils.SetupTestEnvironment(t) |
| 93 | defer env.Cleanup() |
| 94 | |
| 95 | sshDir := filepath.Join(env.TempDir, ".ssh") |
| 96 | require.NoError(t, os.MkdirAll(sshDir, 0700)) |
| 97 | |
| 98 | sshConfigPath := filepath.Join(sshDir, "config") |
| 99 | sshConfig := `Host tnr-first |
| 100 | HostName 192.168.1.100 |
| 101 | User ubuntu |
| 102 | |
| 103 | Host tnr-second |
| 104 | HostName 192.168.1.101 |
| 105 | User ubuntu |
| 106 | ` |
| 107 | |
| 108 | require.NoError(t, os.WriteFile(sshConfigPath, []byte(sshConfig), 0600)) |
| 109 | |
| 110 | err := removeSSHHostEntry(sshConfigPath, "first") |
| 111 | require.NoError(t, err) |
| 112 | |
| 113 | configData, err := os.ReadFile(sshConfigPath) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | configContent := string(configData) |
| 117 | assert.NotContains(t, configContent, "tnr-first") |
| 118 | assert.Contains(t, configContent, "tnr-second") |
| 119 | } |
| 120 | |
| 121 | // TestRemoveSSHHostEntryLastEntry verifies that the removeSSHHostEntry function |
| 122 | // correctly handles removal of the last entry in the SSH config file. |
nothing calls this directly
no test coverage detected