(t *testing.T)
| 335 | } |
| 336 | |
| 337 | func TestCloudID(t *testing.T) { |
| 338 | t.Run("Parse", func(t *testing.T) { |
| 339 | var testdata = []struct { |
| 340 | in string |
| 341 | out string |
| 342 | }{ |
| 343 | { |
| 344 | in: "name:" + base64.StdEncoding.EncodeToString([]byte("host$es_uuid$kibana_uuid")), |
| 345 | out: "https://es_uuid.host", |
| 346 | }, |
| 347 | { |
| 348 | in: "name:" + base64.StdEncoding.EncodeToString([]byte("host:9243$es_uuid$kibana_uuid")), |
| 349 | out: "https://es_uuid.host:9243", |
| 350 | }, |
| 351 | { |
| 352 | in: "name:" + base64.StdEncoding.EncodeToString([]byte("host$es_uuid$")), |
| 353 | out: "https://es_uuid.host", |
| 354 | }, |
| 355 | { |
| 356 | in: "name:" + base64.StdEncoding.EncodeToString([]byte("host$es_uuid")), |
| 357 | out: "https://es_uuid.host", |
| 358 | }, |
| 359 | } |
| 360 | |
| 361 | for _, tt := range testdata { |
| 362 | actual, err := addrFromCloudID(tt.in) |
| 363 | if err != nil { |
| 364 | t.Errorf("Unexpected error: %s", err) |
| 365 | } |
| 366 | if actual != tt.out { |
| 367 | t.Errorf("Unexpected output, want=%q, got=%q", tt.out, actual) |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | }) |
| 372 | |
| 373 | t.Run("Invalid format", func(t *testing.T) { |
| 374 | input := "foobar" |
| 375 | _, err := addrFromCloudID(input) |
| 376 | if err == nil { |
| 377 | t.Errorf("Expected error for input %q, got %v", input, err) |
| 378 | } |
| 379 | match, err := regexp.MatchString("unexpected format", err.Error()) |
| 380 | if err != nil { |
| 381 | t.Fatalf("Unexpected error: %s", err) |
| 382 | } |
| 383 | if !match { |
| 384 | t.Errorf("Unexpected error string: %s", err) |
| 385 | } |
| 386 | }) |
| 387 | |
| 388 | t.Run("Invalid base64 value", func(t *testing.T) { |
| 389 | input := "foobar:xxxxx" |
| 390 | _, err := addrFromCloudID(input) |
| 391 | if err == nil { |
| 392 | t.Errorf("Expected error for input %q, got %v", input, err) |
| 393 | } |
| 394 | match, err := regexp.MatchString("illegal base64 data", err.Error()) |
nothing calls this directly
no test coverage detected