Merge pull request #92 from parrobe/issue91

Fix lint failures in mqmetric tests
This commit is contained in:
Stephen Marshall
2018-05-29 11:39:19 +01:00
committed by GitHub
2 changed files with 16 additions and 16 deletions

View File

@@ -42,7 +42,7 @@ func TestGoldenPathMetric(t *testing.T) {
defer cleanContainer(t, cli, id) defer cleanContainer(t, cli, id)
hostname := getIPAddress(t, cli, id) hostname := getIPAddress(t, cli, id)
port := DEFAULT_METRIC_PORT port := defaultMetricPort
// Now the container is ready we prod the prometheus endpoint until it's up. // Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port) waitForMetricReady(hostname, port)
@@ -90,7 +90,7 @@ func TestMetricNames(t *testing.T) {
defer cleanContainer(t, cli, id) defer cleanContainer(t, cli, id)
hostname := getIPAddress(t, cli, id) hostname := getIPAddress(t, cli, id)
port := DEFAULT_METRIC_PORT port := defaultMetricPort
// Now the container is ready we prod the prometheus endpoint until it's up. // Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port) waitForMetricReady(hostname, port)
@@ -159,7 +159,7 @@ func TestMetricLabels(t *testing.T) {
defer cleanContainer(t, cli, id) defer cleanContainer(t, cli, id)
hostname := getIPAddress(t, cli, id) hostname := getIPAddress(t, cli, id)
port := DEFAULT_METRIC_PORT port := defaultMetricPort
// Now the container is ready we prod the prometheus endpoint until it's up. // Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port) waitForMetricReady(hostname, port)
@@ -226,7 +226,7 @@ func TestRapidFirePrometheus(t *testing.T) {
defer cleanContainer(t, cli, id) defer cleanContainer(t, cli, id)
hostname := getIPAddress(t, cli, id) hostname := getIPAddress(t, cli, id)
port := DEFAULT_METRIC_PORT port := defaultMetricPort
// Now the container is ready we prod the prometheus endpoint until it's up. // Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port) waitForMetricReady(hostname, port)
@@ -283,7 +283,7 @@ func TestSlowPrometheus(t *testing.T) {
defer cleanContainer(t, cli, id) defer cleanContainer(t, cli, id)
hostname := getIPAddress(t, cli, id) hostname := getIPAddress(t, cli, id)
port := DEFAULT_METRIC_PORT port := defaultMetricPort
// Now the container is ready we prod the prometheus endpoint until it's up. // Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port) waitForMetricReady(hostname, port)

View File

@@ -24,25 +24,25 @@ import (
"time" "time"
) )
type MQMETRIC struct { type mqmetric struct {
Key string Key string
Value string Value string
Labels map[string]string Labels map[string]string
} }
const DEFAULT_METRIC_URL = "/metrics" const defaultMetricURL = "/metrics"
const DEFAULT_METRIC_PORT = 9157 const defaultMetricPort = 9157
const DEFAULT_MQ_NAMESPACE = "ibmmq" const defaultMQNamespace = "ibmmq"
func getMetricsFromEndpoint(host string, port int) ([]MQMETRIC, error) { func getMetricsFromEndpoint(host string, port int) ([]mqmetric, error) {
returned := []MQMETRIC{} returned := []mqmetric{}
if host == "" { if host == "" {
return returned, fmt.Errorf("Test Error - Host was nil") return returned, fmt.Errorf("Test Error - Host was nil")
} }
if port <= 0 { if port <= 0 {
return returned, fmt.Errorf("Test Error - port was not above 0") return returned, fmt.Errorf("Test Error - port was not above 0")
} }
urlToUse := fmt.Sprintf("http://%s:%d%s", host, port, DEFAULT_METRIC_URL) urlToUse := fmt.Sprintf("http://%s:%d%s", host, port, defaultMetricURL)
resp, err := http.Get(urlToUse) resp, err := http.Get(urlToUse)
if err != nil { if err != nil {
@@ -58,8 +58,8 @@ func getMetricsFromEndpoint(host string, port int) ([]MQMETRIC, error) {
} }
// Also filters out all non "ibmmq" metrics // Also filters out all non "ibmmq" metrics
func convertRawMetricToMap(input string) ([]MQMETRIC, error) { func convertRawMetricToMap(input string) ([]mqmetric, error) {
returnList := []MQMETRIC{} returnList := []mqmetric{}
if input == "" { if input == "" {
return returnList, fmt.Errorf("Test Error - Raw metric output was nil") return returnList, fmt.Errorf("Test Error - Raw metric output was nil")
} }
@@ -71,7 +71,7 @@ func convertRawMetricToMap(input string) ([]MQMETRIC, error) {
// Comment line of HELP or TYPE. Ignore // Comment line of HELP or TYPE. Ignore
continue continue
} }
if !strings.HasPrefix(line, DEFAULT_MQ_NAMESPACE) { if !strings.HasPrefix(line, defaultMQNamespace) {
// Not an ibmmq_ metric. Ignore // Not an ibmmq_ metric. Ignore
continue continue
} }
@@ -81,7 +81,7 @@ func convertRawMetricToMap(input string) ([]MQMETRIC, error) {
return returnList, fmt.Errorf("ibmmq_ metric could not be deciphered - %v", err) return returnList, fmt.Errorf("ibmmq_ metric could not be deciphered - %v", err)
} }
toAdd := MQMETRIC{ toAdd := mqmetric{
Key: key, Key: key,
Value: value, Value: value,
Labels: labelMap, Labels: labelMap,