| 1 | package ssh_config |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | var validateTests = []struct { |
| 8 | key string |
| 9 | val string |
| 10 | err string |
| 11 | }{ |
| 12 | {"IdentitiesOnly", "yes", ""}, |
| 13 | {"IdentitiesOnly", "Yes", `ssh_config: value for key "IdentitiesOnly" must be 'yes' or 'no', got "Yes"`}, |
| 14 | {"Port", "22", ``}, |
| 15 | {"Port", "yes", `ssh_config: strconv.ParseUint: parsing "yes": invalid syntax`}, |
| 16 | } |
| 17 | |
| 18 | func TestValidate(t *testing.T) { |
| 19 | for _, tt := range validateTests { |
| 20 | err := validate(tt.key, tt.val) |
| 21 | if tt.err == "" && err != nil { |
| 22 | t.Errorf("validate(%q, %q): got %v, want nil", tt.key, tt.val, err) |
| 23 | } |
| 24 | if tt.err != "" { |
| 25 | if err == nil { |
| 26 | t.Errorf("validate(%q, %q): got nil error, want %v", tt.key, tt.val, tt.err) |
| 27 | } else if err.Error() != tt.err { |
| 28 | t.Errorf("validate(%q, %q): got err %v, want %v", tt.key, tt.val, err, tt.err) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestDefault(t *testing.T) { |
| 35 | if v := Default("VisualHostKey"); v != "no" { |
| 36 | t.Errorf("Default(%q): got %v, want 'no'", "VisualHostKey", v) |
| 37 | } |
| 38 | if v := Default("visualhostkey"); v != "no" { |
| 39 | t.Errorf("Default(%q): got %v, want 'no'", "visualhostkey", v) |
| 40 | } |
| 41 | if v := Default("notfound"); v != "" { |
| 42 | t.Errorf("Default(%q): got %v, want ''", "notfound", v) |
| 43 | } |
| 44 | } |