Skip to content

Commit

Permalink
chore: fix new linter errors, reformat, bump license year
Browse files Browse the repository at this point in the history
  • Loading branch information
utkuozdemir committed Oct 21, 2023
1 parent 16cd396 commit 792c3b8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[email protected].
<[email protected]>.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Utku Özdemir
Copyright (c) 2023 Utku Özdemir

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion internal/exporter/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/utkuozdemir/nvidia_gpu_exporter/internal/exporter"
)
Expand All @@ -21,7 +22,7 @@ func TestParseCsvIntoTable(t *testing.T) {

parsed, err := exporter.ParseCSVIntoTable(testCsv, []exporter.QField{"name", "power.draw"})

assert.NoError(t, err)
require.NoError(t, err)
assert.Len(t, parsed.Rows, 2)
assert.Equal(t, []exporter.RField{"name", "power.draw [W]"}, parsed.RFields)

Expand Down
19 changes: 10 additions & 9 deletions internal/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/utkuozdemir/nvidia_gpu_exporter/internal/exporter"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestTransformRawValueValidValues(t *testing.T) {

for raw, expected := range expectedConversions {
val, err := exporter.TransformRawValue(raw, 1)
assert.NoError(t, err)
require.NoError(t, err)
assertFloat(t, expected, val)
}
}
Expand All @@ -62,7 +63,7 @@ func TestTransformRawValueInvalidValues(t *testing.T) {

for _, raw := range rawValues {
_, err := exporter.TransformRawValue(raw, 1)
assert.Error(t, err)
require.Error(t, err)
}
}

Expand All @@ -71,15 +72,15 @@ func TestTransformRawMultiplier(t *testing.T) {

val, err := exporter.TransformRawValue("11", 2)

assert.NoError(t, err)
require.NoError(t, err)
assertFloat(t, 22, val)

val, err = exporter.TransformRawValue("10", 0.5)
assert.NoError(t, err)
require.NoError(t, err)
assertFloat(t, 5, val)

val, err = exporter.TransformRawValue("enabled", 42)
assert.NoError(t, err)
require.NoError(t, err)
assertFloat(t, 1, val)
}

Expand Down Expand Up @@ -171,7 +172,7 @@ func TestNewUnknownField(t *testing.T) {
logger := log.NewNopLogger()
_, err := exporter.New("aaa", "bbb", "a", logger)

assert.Error(t, err)
require.Error(t, err)
}

func TestDescribe(t *testing.T) {
Expand All @@ -180,7 +181,7 @@ func TestDescribe(t *testing.T) {
logger := log.NewNopLogger()
exp, err := exporter.New("aaa", "bbb", "fan.speed,memory.used", logger)

assert.NoError(t, err)
require.NoError(t, err)

doneCh := make(chan bool)
descCh := make(chan *prometheus.Desc)
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestCollect(t *testing.T) {
return nil
}

assert.NoError(t, err)
require.NoError(t, err)

doneCh := make(chan bool)
metricCh := make(chan prometheus.Metric)
Expand Down Expand Up @@ -268,7 +269,7 @@ func TestCollectError(t *testing.T) {
logger := log.NewNopLogger()
exp, err := exporter.New("aaa", "bbb", "fan.speed,memory.used", logger)

assert.NoError(t, err)
require.NoError(t, err)

doneCh := make(chan bool)
metricCh := make(chan prometheus.Metric)
Expand Down
10 changes: 6 additions & 4 deletions internal/exporter/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/utkuozdemir/nvidia_gpu_exporter/internal/exporter"
)
Expand Down Expand Up @@ -78,10 +79,11 @@ func TestParseAutoQFields(t *testing.T) {

fields, err := exporter.ParseAutoQFields("nvidia-smi", command)

assert.Len(t, capturedCmd.Args, 2)
assert.Equal(t, capturedCmd.Args[0], "nvidia-smi")
assert.Equal(t, capturedCmd.Args[1], "--help-query-gpu")
if assert.Len(t, capturedCmd.Args, 2) {
assert.Equal(t, "nvidia-smi", capturedCmd.Args[0])
assert.Equal(t, "--help-query-gpu", capturedCmd.Args[1])
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedQFields, fields)
}
5 changes: 3 additions & 2 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/utkuozdemir/nvidia_gpu_exporter/internal/util"
)
Expand All @@ -22,7 +23,7 @@ func TestHexToDecimal(t *testing.T) {

decimal, err := util.HexToDecimal("0x40051458")

assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, almostEqual(decimal, 1074074712.0))
}

Expand All @@ -31,7 +32,7 @@ func TestHexToDecimalError(t *testing.T) {

_, err := util.HexToDecimal("SOMETHING")

assert.Error(t, err)
require.Error(t, err)
}

func almostEqual(a, b float64) bool {
Expand Down

0 comments on commit 792c3b8

Please sign in to comment.