MCPcopy Create free account
hub / github.com/Driver-C/tryssh / TestLoadConfigFromPath_ValidConfig

Function TestLoadConfigFromPath_ValidConfig

pkg/config/loader_test.go:15–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestLoadConfigFromPath_ValidConfig(t *testing.T) {
16 dir := testutil.TempDir(t)
17 configContent := `main:
18 ports:
19 - "22"
20 - "2222"
21 users:
22 - root
23 - admin
24 passwords:
25 - pass1
26 keys:
27 - /path/to/key
28serverList:
29- ip: 192.168.1.1
30 port: "22"
31 user: root
32 password: pass1
33 alias: server1
34`
35 configPath := testutil.CreateTestConfigFile(t, dir, configContent)
36 knownHostsPath := filepath.Join(dir, "known_hosts")
37
38 conf, err := LoadConfigFromPath(configPath, knownHostsPath)
39 assert.NoError(t, err)
40 assert.NotNil(t, conf)
41
42 assert.Equal(t, []string{"22", "2222"}, conf.Main.Ports)
43 assert.Equal(t, []string{"root", "admin"}, conf.Main.Users)
44 assert.Equal(t, []string{"pass1"}, conf.Main.Passwords)
45 assert.Equal(t, []string{"/path/to/key"}, conf.Main.Keys)
46 assert.Len(t, conf.ServerLists, 1)
47 assert.Equal(t, "192.168.1.1", conf.ServerLists[0].IP)
48 assert.Equal(t, "22", conf.ServerLists[0].Port)
49 assert.Equal(t, "root", conf.ServerLists[0].User)
50 assert.Equal(t, "pass1", conf.ServerLists[0].Password)
51 assert.Equal(t, "server1", conf.ServerLists[0].Alias)
52
53 // known_hosts should have been created
54 assert.FileExists(t, knownHostsPath)
55}
56
57func TestLoadConfigFromPath_MissingConfig_GeneratesNew(t *testing.T) {
58 dir := testutil.TempDir(t)

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
CreateTestConfigFileFunction · 0.92
LoadConfigFromPathFunction · 0.85

Tested by

no test coverage detected