@@ -62,6 +62,22 @@ final class SwiftPrometheusTests: XCTestCase {
6262
6363 XCTAssertEqual ( counter. collect ( ) , " # HELP my_counter Counter for testing \n # TYPE my_counter counter \n my_counter 20 \n my_counter{myValue= \" labels \" } 20 " )
6464 }
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+ }
6581
6682 func testGauge( ) {
6783 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 {
7490 gauge. inc ( 10 , BaseLabels ( myValue: " labels " ) )
7591 XCTAssertEqual ( gauge. get ( ) , 20 )
7692 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 )
7799
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 " )
79101 }
80102
81103 func testHistogram( ) {
82104 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+
83107 histogram. observe ( 1 )
84108 histogram. observe ( 2 )
85- histogram . observe ( 3 )
109+ histogramTwo . observe ( 3 )
86110
87111 histogram. observe ( 3 , . init( myValue: " labels " ) )
88-
112+
89113 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 " )
90114 }
91115
92116 func testSummary( ) {
93117 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)
94119
95120 summary. observe ( 1 )
96121 summary. observe ( 2 )
97122 summary. observe ( 4 )
98- summary . observe ( 10000 )
123+ summaryTwo . observe ( 10000 )
99124
100125 summary. observe ( 123 , . init( myValue: " labels " ) )
101126
0 commit comments