MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / TestRemoveSSHHostEntryFirstEntry

Function TestRemoveSSHHostEntryFirstEntry

cmd/delete_test.go:91–119  ·  view source on GitHub ↗

TestRemoveSSHHostEntryFirstEntry verifies that the removeSSHHostEntry function correctly handles removal of the first entry in the SSH config file.

(t *testing.T)

Source from the content-addressed store, hash-verified

89// TestRemoveSSHHostEntryFirstEntry verifies that the removeSSHHostEntry function
90// correctly handles removal of the first entry in the SSH config file.
91func 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.

Callers

nothing calls this directly

Calls 5

SetupTestEnvironmentFunction · 0.92
removeSSHHostEntryFunction · 0.85
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
ReadFileMethod · 0.65

Tested by

no test coverage detected