Skip to content

Commit

Permalink
Lowercase all errors (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuskoman committed Feb 5, 2024
1 parent 5393cb7 commit eb7085f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 52 deletions.
8 changes: 4 additions & 4 deletions internal/collectors/nodeinfo/nodeinfo_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCollectNotNil(t *testing.T) {
go func() {
err := collector.Collect(ctx, ch)
if err != nil {
t.Errorf("Expected no error, got %v", err)
t.Errorf("expected no error, got %v", err)
}
close(ch)
}()
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestCollectNotNil(t *testing.T) {

for _, expectedMetric := range expectedMetrics {
if !slices.Contains(foundMetrics, expectedMetric) {
t.Errorf("Expected metric %s to be found", expectedMetric)
t.Errorf("expected metric %s to be found", expectedMetric)
}
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestCollectError(t *testing.T) {
close(ch)

if err == nil {
t.Error("Expected err not to be nil")
t.Error("expected err not to be nil")
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ func TestGetUpStatus(t *testing.T) {
status := collector.getUpStatus(test.nodeInfo, test.err)

if status != test.expected {
t.Errorf("Expected up value to be %v, got %v", test.expected, status)
t.Errorf("expected up value to be %v, got %v", test.expected, status)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions internal/collectors/nodestats/nodestats_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestCollectNotNil(t *testing.T) {
go func() {
err := collector.Collect(ctx, ch)
if err != nil {
t.Errorf("Expected no error, got %v", err)
t.Errorf("expected no error, got %v", err)
}
close(ch)
}()
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestCollectNotNil(t *testing.T) {

for _, expectedMetric := range expectedBaseMetrics {
if !slices.Contains(foundMetrics, expectedMetric) {
t.Errorf("Expected metric %s to be found", expectedMetric)
t.Errorf("expected metric %s to be found", expectedMetric)
}
}
}
Expand All @@ -163,7 +163,7 @@ func TestCollectsErrors(t *testing.T) {
close(ch)

if err == nil {
t.Error("Expected err not to be nil")
t.Error("expected err not to be nil")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestIsPipelineHealthy(t *testing.T) {
t.Parallel()
result := collector.isPipelineHealthy(localTestCase.stats)
if result != localTestCase.expected {
t.Errorf("Expected %v, but got %v", localTestCase.expected, result)
t.Errorf("expected %v, but got %v", localTestCase.expected, result)
return
}
})
Expand Down
45 changes: 22 additions & 23 deletions internal/prometheus_helper/prometheus_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func TestExtractValueFromMetric(t *testing.T) {

extractedValue, err := ExtractValueFromMetric(metric)
if err != nil {
t.Errorf("Unexpected error: %v", err)
t.Errorf("unexpected error: %v", err)
}

if extractedValue != metricValue {
t.Errorf("Expected extracted value to be %f, got %f", metricValue, extractedValue)
t.Errorf("expected extracted value to be %f, got %f", metricValue, extractedValue)
}
})

Expand All @@ -89,11 +89,11 @@ func TestExtractValueFromMetric(t *testing.T) {
val, err := ExtractValueFromMetric(badMetric)

if err == nil {
t.Errorf("Expected error, but got nil")
t.Errorf("expected error, but got nil")
}

if val != 0 {
t.Errorf("Expected value to be 0, got %f", val)
t.Errorf("expected value to be 0, got %f", val)
}
})

Expand All @@ -104,11 +104,11 @@ func TestExtractValueFromMetric(t *testing.T) {

val, err := ExtractValueFromMetric(metric)
if err == nil {
t.Errorf("Expected error, but got nil")
t.Errorf("expected error, but got nil")
}

if val != 0 {
t.Errorf("Expected value to be 0, got %f", val)
t.Errorf("expected value to be 0, got %f", val)
}
})
}
Expand All @@ -118,33 +118,33 @@ func TestSimpleMetricsHelper(t *testing.T) {
metricName := "test_metric"
metricDesc := prometheus.NewDesc(metricName, "test metric help", nil, nil)
metricValue := 42.0

ch := make(chan prometheus.Metric)

go func() {
helper := &SimpleMetricsHelper{
Channel: ch,
Labels: []string{},
Labels: []string{},
}
helper.NewFloatMetric(metricDesc, prometheus.GaugeValue, metricValue)
}()

metric := <- ch
metric := <-ch

fqName, err := ExtractFqName(metric.Desc().String())
if err != nil {
t.Errorf("Unexpected error: %v", err)
t.Errorf("unexpected error: %v", err)
}
if metricName != fqName {
t.Errorf("Expected extracted name to be %s, got %s", metricName, fqName)
t.Errorf("expected extracted name to be %s, got %s", metricName, fqName)
}

val, err := ExtractValueFromMetric(metric)
if err != nil {
t.Errorf("Unexpected error: %v", err)
t.Errorf("unexpected error: %v", err)
}
if val != metricValue {
t.Errorf("Expected extracted value to be %f, got %f", metricValue, val)
t.Errorf("expected extracted value to be %f, got %f", metricValue, val)
}
})

Expand All @@ -156,18 +156,18 @@ func TestSimpleMetricsHelper(t *testing.T) {

metricDesc := helper.NewDesc("metric", "help", "customLabel")
metricValue := 42.0

ch := make(chan prometheus.Metric)

go func() {
helper := &SimpleMetricsHelper{
Channel: ch,
Labels: []string{"customLabelValue", "hostnameEndpoint"},
Labels: []string{"customLabelValue", "hostnameEndpoint"},
}
helper.NewFloatMetric(metricDesc, prometheus.GaugeValue, metricValue)
}()

metric := <- ch
metric := <-ch

desc := metric.Desc()
if metricDesc.String() != desc.String() {
Expand All @@ -176,23 +176,23 @@ func TestSimpleMetricsHelper(t *testing.T) {

val, err := ExtractValueFromMetric(metric)
if err != nil {
t.Errorf("Unexpected error: %v", err)
t.Errorf("unexpected error: %v", err)
}
if val != metricValue {
t.Errorf("Expected extracted value to be %f, got %f", metricValue, val)
t.Errorf("expected extracted value to be %f, got %f", metricValue, val)
}
})

t.Run("should create metrics with different value types", func(t *testing.T) {
metricName := "test_metric"
metricDesc := prometheus.NewDesc(metricName, "test metric help", nil, nil)
metricValue := 42.0

ch := make(chan prometheus.Metric, 3)

helper := &SimpleMetricsHelper{
Channel: ch,
Labels: []string{},
Labels: []string{},
}
helper.NewFloatMetric(metricDesc, prometheus.GaugeValue, metricValue)
helper.NewIntMetric(metricDesc, prometheus.GaugeValue, int(metricValue))
Expand All @@ -203,12 +203,11 @@ func TestSimpleMetricsHelper(t *testing.T) {
for metric := range ch {
val, err := ExtractValueFromMetric(metric)
if err != nil {
t.Errorf("Unexpected error: %v", err)
t.Errorf("unexpected error: %v", err)
}
if val != metricValue {
t.Errorf("Expected extracted value to be %f, got %f", metricValue, val)
t.Errorf("expected extracted value to be %f, got %f", metricValue, val)
}
}
})
}

20 changes: 10 additions & 10 deletions pkg/config/slog_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,54 @@ func TestSetupSlog(t *testing.T) {
const LogFormat = defaultLogFormat
logger, err := SetupSlog(LogLevel, LogFormat)
if logger != nil {
t.Errorf("Expected logger to be nil, got %s\"", logger)
t.Errorf("expected logger to be nil, got %s\"", logger)
}
if err.Error() != "slog: level string \"infox\": unknown name" {
t.Errorf("Expected error to be '%s', got %s\"", "slog: level string \"infox\": unknown name", err)
t.Errorf("expected error to be '%s', got %s\"", "slog: level string \"infox\": unknown name", err)
}
})
t.Run("Wrong type of log level", func(t *testing.T) {
const LogLevel = "warn"
const LogFormat = defaultLogFormat
logger, err := SetupSlog(LogLevel, LogFormat)
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
t.Errorf("expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
t.Errorf("expected logger to be not nil, got %s\"", logger)
}
})
t.Run("Wrong type of log format", func(t *testing.T) {
const LogLevel = defaultLogLevel
const LogFormat = "test"
logger, err := SetupSlog(LogLevel, LogFormat)
if logger != nil {
t.Errorf("Expected logger to be nil, got %s\"", logger)
t.Errorf("expected logger to be nil, got %s\"", logger)
}
if !errors.Is(err, ErrUnknownLogFormat) {
t.Errorf("Expected error to be '%s', got %s\"", ErrUnknownLogFormat, err)
t.Errorf("expected error to be '%s', got %s\"", ErrUnknownLogFormat, err)
}
})
t.Run("Correct type of log format", func(t *testing.T) {
const LogLevel = defaultLogLevel
const LogFormat = defaultLogFormat
logger, err := SetupSlog(LogLevel, LogFormat)
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
t.Errorf("expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
t.Errorf("expected logger to be not nil, got %s\"", logger)
}
})
t.Run("Json type of log format", func(t *testing.T) {
const LogLevel = defaultLogLevel
const LogFormat = "json"
logger, err := SetupSlog(LogLevel, LogFormat)
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
t.Errorf("expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
t.Errorf("expected logger to be not nil, got %s\"", logger)
}
})
}
16 changes: 8 additions & 8 deletions pkg/config/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ func TestGetBuildInfo(t *testing.T) {
versionInfo := GetVersionInfo()

if versionInfo.Version == "" {
t.Error("Expected Version to be set")
t.Error("expected Version to be set")
}

if versionInfo.SemanticVersion == "" {
t.Error("Expected SemanticVersion to be set")
t.Error("expected SemanticVersion to be set")
}

if versionInfo.GitCommit == "" {
t.Error("Expected GitCommit to be set")
t.Error("expected GitCommit to be set")
}

if versionInfo.GoVersion != runtime.Version() {
t.Errorf("Expected GoVersion: %s, but got: %s", runtime.Version(), versionInfo.GoVersion)
t.Errorf("expected GoVersion: %s, but got: %s", runtime.Version(), versionInfo.GoVersion)
}

if versionInfo.BuildArch != runtime.GOARCH {
t.Errorf("Expected BuildArch: %s, but got: %s", runtime.GOARCH, versionInfo.BuildArch)
t.Errorf("expected BuildArch: %s, but got: %s", runtime.GOARCH, versionInfo.BuildArch)
}

if versionInfo.BuildOS != runtime.GOOS {
t.Errorf("Expected BuildOS: %s, but got: %s", runtime.GOOS, versionInfo.BuildOS)
t.Errorf("expected BuildOS: %s, but got: %s", runtime.GOOS, versionInfo.BuildOS)
}

if versionInfo.BuildDate == "" {
t.Error("Expected BuildDate to be set")
t.Error("expected BuildDate to be set")
}
}

Expand All @@ -52,6 +52,6 @@ func TestVersionInfoString(t *testing.T) {
versionInfoString := versionInfo.String()

if versionInfoString != expectedString {
t.Errorf("Expected string: %s, but got: %s", expectedString, versionInfoString)
t.Errorf("expected string: %s, but got: %s", expectedString, versionInfoString)
}
}
6 changes: 3 additions & 3 deletions pkg/manager/collector_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestCollect(t *testing.T) {

select {
case <-ch:
t.Error("Expected no metric to be sent to the channel")
t.Error("expected no metric to be sent to the channel")
case <-func() chan struct{} {
done := make(chan struct{})
go func() {
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestCollect(t *testing.T) {
desc := metric.Desc()
expectedDesc := "Desc{fqName: \"mock_metric\", help: \"mock metric description\", constLabels: {}, variableLabels: {}}"
if desc.String() != expectedDesc {
t.Errorf("Expected metric description to be '%s', got %s", expectedDesc, desc.String())
t.Errorf("expected metric description to be '%s', got %s", expectedDesc, desc.String())
}
})
}
Expand All @@ -127,6 +127,6 @@ func TestDescribe(t *testing.T) {
desc := <-ch
expectedDesc := "Desc{fqName: \"logstash_exporter_scrape_duration_seconds\", help: \"logstash_exporter: Duration of a scrape job.\", constLabels: {}, variableLabels: {collector,result}}"
if desc.String() != expectedDesc {
t.Errorf("Expected metric description to be '%s', got %s", expectedDesc, desc.String())
t.Errorf("expected metric description to be '%s', got %s", expectedDesc, desc.String())
}
}

0 comments on commit eb7085f

Please sign in to comment.