| 119 | } |
| 120 | |
| 121 | func TestProject(t *testing.T) { |
| 122 | tests := []struct { |
| 123 | name string |
| 124 | projectName string |
| 125 | shouldHaveQuery bool |
| 126 | expectedValue string |
| 127 | }{ |
| 128 | { |
| 129 | name: "empty project name", |
| 130 | projectName: "", |
| 131 | shouldHaveQuery: false, |
| 132 | }, |
| 133 | { |
| 134 | name: "default project", |
| 135 | projectName: "default", |
| 136 | shouldHaveQuery: false, |
| 137 | }, |
| 138 | { |
| 139 | name: "custom project", |
| 140 | projectName: "my-project", |
| 141 | shouldHaveQuery: true, |
| 142 | expectedValue: "my-project", |
| 143 | }, |
| 144 | } |
| 145 | |
| 146 | for _, tt := range tests { |
| 147 | t.Run(tt.name, func(t *testing.T) { |
| 148 | u := NewURL().Project(tt.projectName) |
| 149 | query := u.Query() |
| 150 | |
| 151 | if tt.shouldHaveQuery { |
| 152 | if !query.Has("project") { |
| 153 | t.Error("Expected query to have 'project' parameter") |
| 154 | } |
| 155 | |
| 156 | if query.Get("project") != tt.expectedValue { |
| 157 | t.Errorf("Expected project value %q, got %q", tt.expectedValue, query.Get("project")) |
| 158 | } |
| 159 | } else { |
| 160 | if query.Has("project") { |
| 161 | t.Errorf("Expected query to not have 'project' parameter, but got %q", query.Get("project")) |
| 162 | } |
| 163 | } |
| 164 | }) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | func TestTarget(t *testing.T) { |
| 169 | tests := []struct { |