(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func TestEncode(t *testing.T) { |
| 107 | var buff bytes.Buffer |
| 108 | delimEncoder := NewEncoder(&buff, FmtProtoDelim) |
| 109 | metric := &dto.MetricFamily{ |
| 110 | Name: proto.String("foo_metric"), |
| 111 | Type: dto.MetricType_UNTYPED.Enum(), |
| 112 | Metric: []*dto.Metric{ |
| 113 | { |
| 114 | Untyped: &dto.Untyped{ |
| 115 | Value: proto.Float64(1.234), |
| 116 | }, |
| 117 | }, |
| 118 | }, |
| 119 | } |
| 120 | |
| 121 | err := delimEncoder.Encode(metric) |
| 122 | if err != nil { |
| 123 | t.Errorf("unexpected error during encode: %s", err.Error()) |
| 124 | } |
| 125 | |
| 126 | out := buff.Bytes() |
| 127 | if len(out) == 0 { |
| 128 | t.Errorf("expected the output bytes buffer to be non-empty") |
| 129 | } |
| 130 | |
| 131 | buff.Reset() |
| 132 | |
| 133 | compactEncoder := NewEncoder(&buff, FmtProtoCompact) |
| 134 | err = compactEncoder.Encode(metric) |
| 135 | if err != nil { |
| 136 | t.Errorf("unexpected error during encode: %s", err.Error()) |
| 137 | } |
| 138 | |
| 139 | out = buff.Bytes() |
| 140 | if len(out) == 0 { |
| 141 | t.Errorf("expected the output bytes buffer to be non-empty") |
| 142 | } |
| 143 | |
| 144 | buff.Reset() |
| 145 | |
| 146 | protoTextEncoder := NewEncoder(&buff, FmtProtoText) |
| 147 | err = protoTextEncoder.Encode(metric) |
| 148 | if err != nil { |
| 149 | t.Errorf("unexpected error during encode: %s", err.Error()) |
| 150 | } |
| 151 | |
| 152 | out = buff.Bytes() |
| 153 | if len(out) == 0 { |
| 154 | t.Errorf("expected the output bytes buffer to be non-empty") |
| 155 | } |
| 156 | |
| 157 | buff.Reset() |
| 158 | |
| 159 | textEncoder := NewEncoder(&buff, FmtText) |
| 160 | err = textEncoder.Encode(metric) |
| 161 | if err != nil { |
| 162 | t.Errorf("unexpected error during encode: %s", err.Error()) |
| 163 | } |
nothing calls this directly
no test coverage detected