| 1 |
// Copyright 2018 The Prometheus Authors |
| 2 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 |
// you may not use this file except in compliance with the License. |
| 4 |
// You may obtain a copy of the License at |
| 5 |
// |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package prometheus |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
) |
| 19 |
|
| 20 |
func TestNewDescInvalidLabelValues(t *testing.T) { |
| 21 |
desc := NewDesc( |
| 22 |
"sample_label", |
| 23 |
"sample label", |
| 24 |
nil, |
| 25 |
Labels{"a": "\xFF"}, |
| 26 |
) |
| 27 |
if desc.err == nil { |
| 28 |
t.Errorf("NewDesc: expected error because: %s", desc.err) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
func TestNewDescNilLabelValues(t *testing.T) { |
| 33 |
desc := NewDesc( |
| 34 |
"sample_label", |
| 35 |
"sample label", |
| 36 |
nil, |
| 37 |
nil, |
| 38 |
) |
| 39 |
if desc.err != nil { |
| 40 |
t.Errorf("NewDesc: unexpected error: %s", desc.err) |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
func TestNewDescWithNilLabelValues_String(t *testing.T) { |
| 45 |
desc := NewDesc( |
| 46 |
"sample_label", |
| 47 |
"sample label", |
| 48 |
nil, |
| 49 |
nil, |
| 50 |
) |
| 51 |
if desc.String() != `Desc{fqName: "sample_label", help: "sample label", constLabels: {}, variableLabels: {}}` { |
| 52 |
t.Errorf("String: unexpected output: %s", desc.String()) |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
func TestNewInvalidDesc_String(t *testing.T) { |
| 57 |
desc := NewInvalidDesc( |
| 58 |
nil, |
| 59 |
) |
| 60 |
if desc.String() != `Desc{fqName: "", help: "", constLabels: {}, variableLabels: {}}` { |
| 61 |
t.Errorf("String: unexpected output: %s", desc.String()) |
| 62 |
} |
| 63 |
} |