@@ -62,6 +62,22 @@ final class SwiftPrometheusTests: XCTestCase {
62
62
63
63
XCTAssertEqual ( counter. collect ( ) , " # HELP my_counter Counter for testing \n # TYPE my_counter counter \n my_counter 20 \n my_counter{myValue= \" labels \" } 20 " )
64
64
}
65
+
66
+ func testMultipleCounter( ) {
67
+ let counter = prom. createCounter ( forType: Int . self, named: " my_counter " , helpText: " Counter for testing " , initialValue: 10 , withLabelType: BaseLabels . self)
68
+ counter. inc ( 10 )
69
+ XCTAssertEqual ( counter. get ( ) , 20 )
70
+
71
+ let counterTwo = prom. createCounter ( forType: Int . self, named: " my_counter " , helpText: " Counter for testing " , initialValue: 10 , withLabelType: BaseLabels . self)
72
+ counter. inc ( 10 )
73
+ XCTAssertEqual ( counterTwo. get ( ) , 30 )
74
+ counterTwo. inc ( 20 , BaseLabels ( myValue: " labels " ) )
75
+
76
+ XCTAssertEqual ( counter. collect ( ) , " # HELP my_counter Counter for testing \n # TYPE my_counter counter \n my_counter 30 \n my_counter{myValue= \" labels \" } 30 " )
77
+ self . prom. collect { metricsString in
78
+ XCTAssertEqual ( metricsString, " # HELP my_counter Counter for testing \n # TYPE my_counter counter \n my_counter 30 \n my_counter{myValue= \" labels \" } 30 " )
79
+ }
80
+ }
65
81
66
82
func testGauge( ) {
67
83
let gauge = prom. createGauge ( forType: Int . self, named: " my_gauge " , helpText: " Gauge for testing " , initialValue: 10 , withLabelType: BaseLabels . self)
@@ -74,28 +90,37 @@ final class SwiftPrometheusTests: XCTestCase {
74
90
gauge. inc ( 10 , BaseLabels ( myValue: " labels " ) )
75
91
XCTAssertEqual ( gauge. get ( ) , 20 )
76
92
XCTAssertEqual ( gauge. get ( BaseLabels ( myValue: " labels " ) ) , 20 )
93
+
94
+ let gaugeTwo = prom. createGauge ( forType: Int . self, named: " my_gauge " , helpText: " Gauge for testing " , initialValue: 10 , withLabelType: BaseLabels . self)
95
+ XCTAssertEqual ( gaugeTwo. get ( ) , 20 )
96
+ gaugeTwo. inc ( )
97
+ XCTAssertEqual ( gauge. get ( ) , 21 )
98
+ XCTAssertEqual ( gaugeTwo. get ( ) , 21 )
77
99
78
- XCTAssertEqual ( gauge. collect ( ) , " # HELP my_gauge Gauge for testing \n # TYPE my_gauge gauge \n my_gauge 20 \n my_gauge{myValue= \" labels \" } 20 " )
100
+ XCTAssertEqual ( gauge. collect ( ) , " # HELP my_gauge Gauge for testing \n # TYPE my_gauge gauge \n my_gauge 21 \n my_gauge{myValue= \" labels \" } 20 " )
79
101
}
80
102
81
103
func testHistogram( ) {
82
104
let histogram = prom. createHistogram ( forType: Double . self, named: " my_histogram " , helpText: " Histogram for testing " , buckets: [ 0.5 , 1 , 2 , 3 , 5 , Double . greatestFiniteMagnitude] , labels: BaseHistogramLabels . self)
105
+ let histogramTwo = prom. createHistogram ( forType: Double . self, named: " my_histogram " , helpText: " Histogram for testing " , buckets: [ 0.5 , 1 , 2 , 3 , 5 , Double . greatestFiniteMagnitude] , labels: BaseHistogramLabels . self)
106
+
83
107
histogram. observe ( 1 )
84
108
histogram. observe ( 2 )
85
- histogram . observe ( 3 )
109
+ histogramTwo . observe ( 3 )
86
110
87
111
histogram. observe ( 3 , . init( myValue: " labels " ) )
88
-
112
+
89
113
XCTAssertEqual ( histogram. collect ( ) , " # HELP my_histogram Histogram for testing \n # TYPE my_histogram histogram \n my_histogram_bucket{myValue= \" * \" , le= \" 0.5 \" } 0.0 \n my_histogram_bucket{myValue= \" * \" , le= \" 1.0 \" } 1.0 \n my_histogram_bucket{myValue= \" * \" , le= \" 2.0 \" } 2.0 \n my_histogram_bucket{myValue= \" * \" , le= \" 3.0 \" } 4.0 \n my_histogram_bucket{myValue= \" * \" , le= \" 5.0 \" } 4.0 \n my_histogram_bucket{myValue= \" * \" , le= \" +Inf \" } 4.0 \n my_histogram_count{myValue= \" * \" } 4.0 \n my_histogram_sum{myValue= \" * \" } 9.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" 0.5 \" } 0.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" 1.0 \" } 0.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" 2.0 \" } 0.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" 3.0 \" } 1.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" 5.0 \" } 1.0 \n my_histogram_bucket{myValue= \" labels \" , le= \" +Inf \" } 1.0 \n my_histogram_count{myValue= \" labels \" } 1.0 \n my_histogram_sum{myValue= \" labels \" } 3.0 " )
90
114
}
91
115
92
116
func testSummary( ) {
93
117
let summary = prom. createSummary ( forType: Double . self, named: " my_summary " , helpText: " Summary for testing " , quantiles: [ 0.5 , 0.9 , 0.99 ] , labels: BaseSummaryLabels . self)
118
+ let summaryTwo = prom. createSummary ( forType: Double . self, named: " my_summary " , helpText: " Summary for testing " , quantiles: [ 0.5 , 0.9 , 0.99 ] , labels: BaseSummaryLabels . self)
94
119
95
120
summary. observe ( 1 )
96
121
summary. observe ( 2 )
97
122
summary. observe ( 4 )
98
- summary . observe ( 10000 )
123
+ summaryTwo . observe ( 10000 )
99
124
100
125
summary. observe ( 123 , . init( myValue: " labels " ) )
101
126
0 commit comments