(t *testing.T)
| 145 | } |
| 146 | |
| 147 | func TestEditConfig(t *testing.T) { |
| 148 | tmpDir, fname := settingsDirAndFile(t) |
| 149 | defer os.RemoveAll(tmpDir) |
| 150 | |
| 151 | type testConfig struct { |
| 152 | name string |
| 153 | focus string |
| 154 | hide string |
| 155 | } |
| 156 | type testCase struct { |
| 157 | remove bool |
| 158 | request string |
| 159 | expect []testConfig |
| 160 | } |
| 161 | for _, c := range []testCase{ |
| 162 | // Create setting c1 |
| 163 | {false, "/?config=c1&f=foo", []testConfig{ |
| 164 | {"c1", "foo", ""}, |
| 165 | }}, |
| 166 | // Create setting c2 |
| 167 | {false, "/?config=c2&h=bar", []testConfig{ |
| 168 | {"c1", "foo", ""}, |
| 169 | {"c2", "", "bar"}, |
| 170 | }}, |
| 171 | // Overwrite c1 |
| 172 | {false, "/?config=c1&f=baz", []testConfig{ |
| 173 | {"c1", "baz", ""}, |
| 174 | {"c2", "", "bar"}, |
| 175 | }}, |
| 176 | // Delete c2 |
| 177 | {true, "c2", []testConfig{ |
| 178 | {"c1", "baz", ""}, |
| 179 | }}, |
| 180 | } { |
| 181 | if c.remove { |
| 182 | if err := removeConfig(fname, c.request); err != nil { |
| 183 | t.Errorf("error removing config %s: %v", c.request, err) |
| 184 | continue |
| 185 | } |
| 186 | } else { |
| 187 | req, err := url.Parse(c.request) |
| 188 | if err != nil { |
| 189 | t.Errorf("error parsing request %q: %v", c.request, err) |
| 190 | continue |
| 191 | } |
| 192 | if err := setConfig(fname, *req); err != nil { |
| 193 | t.Errorf("error saving request %q: %v", c.request, err) |
| 194 | continue |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Check resulting settings. |
| 199 | s, err := readSettings(fname) |
| 200 | if err != nil { |
| 201 | t.Errorf("error reading settings after applying %q: %v", c.request, err) |
| 202 | continue |
| 203 | } |
| 204 | // Convert to a list that can be compared to c.expect |
nothing calls this directly
no test coverage detected
searching dependent graphs…