(t *testing.T)
| 626 | } |
| 627 | |
| 628 | func TestCreateError(t *testing.T) { |
| 629 | scenarios := []struct { |
| 630 | in *dto.MetricFamily |
| 631 | err string |
| 632 | }{ |
| 633 | // 0: No metric. |
| 634 | { |
| 635 | in: &dto.MetricFamily{ |
| 636 | Name: proto.String("name"), |
| 637 | Help: proto.String("doc string"), |
| 638 | Type: dto.MetricType_COUNTER.Enum(), |
| 639 | Metric: []*dto.Metric{}, |
| 640 | }, |
| 641 | err: "MetricFamily has no metrics", |
| 642 | }, |
| 643 | // 1: No metric name. |
| 644 | { |
| 645 | in: &dto.MetricFamily{ |
| 646 | Help: proto.String("doc string"), |
| 647 | Type: dto.MetricType_UNTYPED.Enum(), |
| 648 | Metric: []*dto.Metric{ |
| 649 | { |
| 650 | Untyped: &dto.Untyped{ |
| 651 | Value: proto.Float64(math.Inf(-1)), |
| 652 | }, |
| 653 | }, |
| 654 | }, |
| 655 | }, |
| 656 | err: "MetricFamily has no name", |
| 657 | }, |
| 658 | // 2: Wrong type. |
| 659 | { |
| 660 | in: &dto.MetricFamily{ |
| 661 | Name: proto.String("name"), |
| 662 | Help: proto.String("doc string"), |
| 663 | Type: dto.MetricType_COUNTER.Enum(), |
| 664 | Metric: []*dto.Metric{ |
| 665 | { |
| 666 | Untyped: &dto.Untyped{ |
| 667 | Value: proto.Float64(math.Inf(-1)), |
| 668 | }, |
| 669 | }, |
| 670 | }, |
| 671 | }, |
| 672 | err: "expected counter in metric", |
| 673 | }, |
| 674 | } |
| 675 | |
| 676 | for i, scenario := range scenarios { |
| 677 | var out bytes.Buffer |
| 678 | _, err := MetricFamilyToText(&out, scenario.in) |
| 679 | if err == nil { |
| 680 | t.Errorf("%d. expected error, got nil", i) |
| 681 | continue |
| 682 | } |
| 683 | if expected, got := scenario.err, err.Error(); strings.Index(got, expected) != 0 { |
| 684 | t.Errorf( |
| 685 | "%d. expected error starting with %q, got %q", |
nothing calls this directly
no test coverage detected