11package collectors
22
3-
43import (
4+ "encoding/json"
55 "fmt"
6- "testing"
7- "regexp"
8- "strings"
96 "net/http"
107 "net/http/httptest"
11- "encoding/json"
128 "os"
9+ "regexp"
10+ "strings"
11+ "testing"
1312
14- "purestorage/fa-openmetrics-exporter/internal/rest-client"
13+ client "purestorage/fa-openmetrics-exporter/internal/rest-client"
1514)
1615
1716func TestDriveCollector (t * testing.T ) {
@@ -21,27 +20,27 @@ func TestDriveCollector(t *testing.T) {
2120 var drl client.DriveList
2221 json .Unmarshal (rdr , & drl )
2322 server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
24- url := regexp .MustCompile (`^/api/([0-9]+.[0-9]+)?/drive$` )
25- if r .URL .Path == "/api/api_version" {
26- w .Header ().Set ("Content-Type" , "application/json" )
27- w .WriteHeader (http .StatusOK )
23+ url := regexp .MustCompile (`^/api/([0-9]+.[0-9]+)?/drive$` )
24+ if r .URL .Path == "/api/api_version" {
25+ w .Header ().Set ("Content-Type" , "application/json" )
26+ w .WriteHeader (http .StatusOK )
2827 w .Write ([]byte (vers ))
29- } else if url .MatchString (r .URL .Path ) {
28+ } else if url .MatchString (r .URL .Path ) {
3029 w .Header ().Set ("x-auth-token" , "faketoken" )
3130 w .Header ().Set ("Content-Type" , "application/json" )
3231 w .WriteHeader (http .StatusOK )
3332 w .Write ([]byte (rdr ))
3433 }
35- }))
36- endp := strings .Split (server .URL , "/" )
37- e := endp [len (endp )- 1 ]
34+ }))
35+ endp := strings .Split (server .URL , "/" )
36+ e := endp [len (endp )- 1 ]
3837 want := make (map [string ]bool )
3938 for _ , d := range drl .Items {
40- want [fmt .Sprintf ("label:{name:\" component_name\" value:\" %s\" } label:{name:\" component_status\" value:\" %s\" } label:{name:\" component_type\" value:\" %s\" } label:{name:\" component_type\" value:\" %s\" } gauge:{value:\" %s\" }" , d .Name , d .Type , d .Status , d .Protocol , d .Capacity )] = true
41- }
39+ want [fmt .Sprintf ("label:{name:\" component_name\" value:\" %s\" } label:{name:\" component_status\" value:\" %s\" } label:{name:\" component_type\" value:\" %s\" } label:{name:\" component_type\" value:\" %s\" } gauge:{value:\" %g\" }" , d .Name , d .Type , d .Status , d .Protocol , d .Capacity )] = true
4240 }
43- c := client .NewRestClient (e , "fake-api-token" , "latest" , false )
41+
42+ c := client .NewRestClient (e , "fake-api-token" , "latest" , false )
4443 dc := NewDriveCollector (c )
45- metricsCheck (t , dc , want )
46- server .Close ()
44+ metricsCheck (t , dc , want )
45+ server .Close ()
4746}
0 commit comments