1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
package telemetry
import (
"testing"
)
func TestHistogramCreation(t *testing.T) {
histogramName := "request_duration"
histogramUnit := "milliseconds"
histogramDescription := "The duration of client requests."
histogram := &Histogram{
Name: histogramName,
Unit: histogramUnit,
Description: histogramDescription,
}
if histogram.GetName() != histogramName {
t.Errorf("Expected Histogram Name to be '%s', but got '%s'", histogramName, histogram.GetName())
}
if histogram.GetUnit() != histogramUnit {
t.Errorf("Expected Histogram Unit to be '%s', but got '%s'", histogramUnit, histogram.GetUnit())
}
if histogram.GetDescription() != histogramDescription {
t.Errorf("Expected Histogram Description to be '%s', but got '%s'", histogramDescription, histogram.GetDescription())
}
}
func TestEmptyHistogramCreation(t *testing.T) {
histogram := &Histogram{}
if histogram.GetName() != "" {
t.Errorf("Expected Histogram Name to be empty, but got '%s'", histogram.GetName())
}
if histogram.GetUnit() != "" {
t.Errorf("Expected Histogram Unit to be empty, but got '%s'", histogram.GetUnit())
}
if histogram.GetDescription() != "" {
t.Errorf("Expected Histogram Description to be empty, but got '%s'", histogram.GetDescription())
}
}
func TestHistogramWithSpecialCharacters(t *testing.T) {
histogramName := "request_duration!@#$%"
histogramUnit := "ms!@#$%"
histogramDescription := "The duration of client requests!@#$%."
histogram := &Histogram{
Name: histogramName,
Unit: histogramUnit,
Description: histogramDescription,
}
if histogram.GetName() != histogramName {
t.Errorf("Expected Histogram Name to be '%s', but got '%s'", histogramName, histogram.GetName())
}
if histogram.GetUnit() != histogramUnit {
t.Errorf("Expected Histogram Unit to be '%s', but got '%s'", histogramUnit, histogram.GetUnit())
}
if histogram.GetDescription() != histogramDescription {
t.Errorf("Expected Histogram Description to be '%s', but got '%s'", histogramDescription, histogram.GetDescription())
}
}
func TestHistogramWithLongStrings(t *testing.T) {
histogramName := "this_is_a_very_long_histogram_name_to_test_edge_cases_in_the_telemetry_module"
histogramUnit := "milliseconds_with_long_unit_name"
histogramDescription := "This is a very long description to test how the Histogram struct handles long strings in the telemetry module."
histogram := &Histogram{
Name: histogramName,
Unit: histogramUnit,
Description: histogramDescription,
}
if histogram.GetName() != histogramName {
t.Errorf("Expected Histogram Name to be '%s', but got '%s'", histogramName, histogram.GetName())
}
if histogram.GetUnit() != histogramUnit {
t.Errorf("Expected Histogram Unit to be '%s', but got '%s'", histogramUnit, histogram.GetUnit())
}
if histogram.GetDescription() != histogramDescription {
t.Errorf("Expected Histogram Description to be '%s', but got '%s'", histogramDescription, histogram.GetDescription())
}
}
|