TestWithNameFailure tests cases where WithName should fail. Cases where it should succeed are covered by TestSplitHostname, below.
(t *testing.T)
| 237 | // TestWithNameFailure tests cases where WithName should fail. Cases where it |
| 238 | // should succeed are covered by TestSplitHostname, below. |
| 239 | func TestWithNameFailure(t *testing.T) { |
| 240 | testcases := []struct { |
| 241 | input string |
| 242 | err error |
| 243 | }{ |
| 244 | { |
| 245 | input: "", |
| 246 | err: ErrNameEmpty, |
| 247 | }, |
| 248 | { |
| 249 | input: ":justtag", |
| 250 | err: ErrReferenceInvalidFormat, |
| 251 | }, |
| 252 | { |
| 253 | input: "@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", |
| 254 | err: ErrReferenceInvalidFormat, |
| 255 | }, |
| 256 | { |
| 257 | input: "validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", |
| 258 | err: ErrReferenceInvalidFormat, |
| 259 | }, |
| 260 | { |
| 261 | input: strings.Repeat("a/", 128) + "a:tag", |
| 262 | err: ErrNameTooLong, |
| 263 | }, |
| 264 | { |
| 265 | input: "aa/asdf$$^/aa", |
| 266 | err: ErrReferenceInvalidFormat, |
| 267 | }, |
| 268 | } |
| 269 | for _, testcase := range testcases { |
| 270 | failf := func(format string, v ...interface{}) { |
| 271 | t.Logf(strconv.Quote(testcase.input)+": "+format, v...) |
| 272 | t.Fail() |
| 273 | } |
| 274 | |
| 275 | _, err := WithName(testcase.input) |
| 276 | if err == nil { |
| 277 | failf("no error parsing name. expected: %s", testcase.err) |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | func TestSplitHostname(t *testing.T) { |
| 283 | testcases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…