(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func TestUpdateConfigAtPath(t *testing.T) { |
| 155 | dir := testutil.TempDir(t) |
| 156 | configPath := filepath.Join(dir, ".tryssh", ConfigFileName) |
| 157 | err := os.MkdirAll(filepath.Dir(configPath), 0755) |
| 158 | assert.NoError(t, err) |
| 159 | |
| 160 | conf := &MainConfig{} |
| 161 | conf.Main.Ports = []string{"22", "2222"} |
| 162 | conf.Main.Users = []string{"root"} |
| 163 | conf.Main.Passwords = []string{"secret"} |
| 164 | conf.Main.Keys = []string{"/home/user/.ssh/id_rsa"} |
| 165 | conf.ServerLists = []ServerListConfig{ |
| 166 | { |
| 167 | IP: "10.0.0.1", |
| 168 | Port: "22", |
| 169 | User: "root", |
| 170 | Password: "secret", |
| 171 | Alias: "myserver", |
| 172 | }, |
| 173 | } |
| 174 | |
| 175 | err = UpdateConfigAtPath(configPath, conf) |
| 176 | assert.NoError(t, err) |
| 177 | |
| 178 | // Verify the written file can be parsed back |
| 179 | data, err := os.ReadFile(configPath) |
| 180 | assert.NoError(t, err) |
| 181 | |
| 182 | var loaded MainConfig |
| 183 | err = yaml.Unmarshal(data, &loaded) |
| 184 | assert.NoError(t, err) |
| 185 | assert.Equal(t, conf.Main.Ports, loaded.Main.Ports) |
| 186 | assert.Equal(t, conf.Main.Users, loaded.Main.Users) |
| 187 | assert.Equal(t, conf.Main.Passwords, loaded.Main.Passwords) |
| 188 | assert.Equal(t, conf.Main.Keys, loaded.Main.Keys) |
| 189 | assert.Len(t, loaded.ServerLists, 1) |
| 190 | assert.Equal(t, "10.0.0.1", loaded.ServerLists[0].IP) |
| 191 | assert.Equal(t, "myserver", loaded.ServerLists[0].Alias) |
| 192 | } |
| 193 | |
| 194 | func TestUpdateConfigAtPath_InvalidPath(t *testing.T) { |
| 195 | // Use a path in a non-existent directory that cannot be created |
nothing calls this directly
no test coverage detected