| 27 | ) |
| 28 | |
| 29 | func TestCloneRepo(t *testing.T) { |
| 30 | t.Parallel() |
| 31 | |
| 32 | for _, tc := range []struct { |
| 33 | name string |
| 34 | srvUsername string |
| 35 | srvPassword string |
| 36 | username string |
| 37 | password string |
| 38 | mungeURL func(*string) |
| 39 | expectError string |
| 40 | expectClone bool |
| 41 | }{ |
| 42 | { |
| 43 | name: "no auth", |
| 44 | expectClone: true, |
| 45 | }, |
| 46 | { |
| 47 | name: "auth", |
| 48 | srvUsername: "user", |
| 49 | srvPassword: "password", |
| 50 | username: "user", |
| 51 | password: "password", |
| 52 | expectClone: true, |
| 53 | }, |
| 54 | { |
| 55 | name: "auth but no creds", |
| 56 | srvUsername: "user", |
| 57 | srvPassword: "password", |
| 58 | expectClone: false, |
| 59 | expectError: "authentication required", |
| 60 | }, |
| 61 | { |
| 62 | name: "invalid auth", |
| 63 | srvUsername: "user", |
| 64 | srvPassword: "password", |
| 65 | username: "notuser", |
| 66 | password: "notpassword", |
| 67 | expectClone: false, |
| 68 | expectError: "authentication required", |
| 69 | }, |
| 70 | { |
| 71 | name: "tokenish username", |
| 72 | srvUsername: "tokentokentoken", |
| 73 | srvPassword: "", |
| 74 | username: "tokentokentoken", |
| 75 | password: "", |
| 76 | expectClone: true, |
| 77 | }, |
| 78 | { |
| 79 | name: "whitespace in URL", |
| 80 | mungeURL: func(u *string) { |
| 81 | if u == nil { |
| 82 | t.Errorf("expected non-nil URL") |
| 83 | return |
| 84 | } |
| 85 | *u = " " + *u + " " |
| 86 | t.Logf("munged URL: %q", *u) |