(t *testing.T)
| 495 | } |
| 496 | |
| 497 | func TestCreateError(t *testing.T) { |
| 498 | scenarios := []struct { |
| 499 | in *dto.MetricFamily |
| 500 | err string |
| 501 | }{ |
| 502 | // 0: No metric. |
| 503 | { |
| 504 | in: &dto.MetricFamily{ |
| 505 | Name: proto.String("name"), |
| 506 | Help: proto.String("doc string"), |
| 507 | Type: dto.MetricType_COUNTER.Enum(), |
| 508 | Metric: []*dto.Metric{}, |
| 509 | }, |
| 510 | err: "MetricFamily has no metrics", |
| 511 | }, |
| 512 | // 1: No metric name. |
| 513 | { |
| 514 | in: &dto.MetricFamily{ |
| 515 | Help: proto.String("doc string"), |
| 516 | Type: dto.MetricType_UNTYPED.Enum(), |
| 517 | Metric: []*dto.Metric{ |
| 518 | { |
| 519 | Untyped: &dto.Untyped{ |
| 520 | Value: proto.Float64(math.Inf(-1)), |
| 521 | }, |
| 522 | }, |
| 523 | }, |
| 524 | }, |
| 525 | err: "MetricFamily has no name", |
| 526 | }, |
| 527 | // 2: Wrong type. |
| 528 | { |
| 529 | in: &dto.MetricFamily{ |
| 530 | Name: proto.String("name"), |
| 531 | Help: proto.String("doc string"), |
| 532 | Type: dto.MetricType_COUNTER.Enum(), |
| 533 | Metric: []*dto.Metric{ |
| 534 | { |
| 535 | Untyped: &dto.Untyped{ |
| 536 | Value: proto.Float64(math.Inf(-1)), |
| 537 | }, |
| 538 | }, |
| 539 | }, |
| 540 | }, |
| 541 | err: "expected counter in metric", |
| 542 | }, |
| 543 | } |
| 544 | |
| 545 | for i, scenario := range scenarios { |
| 546 | var out bytes.Buffer |
| 547 | _, err := MetricFamilyToText(&out, scenario.in) |
| 548 | if err == nil { |
| 549 | t.Errorf("%d. expected error, got nil", i) |
| 550 | continue |
| 551 | } |
| 552 | if expected, got := scenario.err, err.Error(); strings.Index(got, expected) != 0 { |
| 553 | t.Errorf( |
| 554 | "%d. expected error starting with %q, got %q", |
nothing calls this directly
no test coverage detected