forked from utkuozdemir/nvidia_gpu_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
59 lines (42 loc) · 1023 Bytes
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package exporter
import (
"fmt"
"math"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestToSnakeCase(t *testing.T) {
t.Parallel()
snakeCase := toSnakeCase("aaaAAA_aaaAaa")
assert.Equal(t, "aaa_aaa_aaa_aaa", snakeCase)
}
func TestHexToDecimal(t *testing.T) {
t.Parallel()
decimal, err := hexToDecimal("0x40051458")
assert.NoError(t, err)
assert.True(t, almostEqual(decimal, 1074074712.0))
}
func TestHexToDecimalError(t *testing.T) {
t.Parallel()
_, err := hexToDecimal("SOMETHING")
assert.Error(t, err)
}
func almostEqual(a, b float64) bool {
return math.Abs(a-b) <= 1e-9
}
// TestParseQueryFields is ran manually.
//nolint:forbidigo
func TestParseQueryFields(t *testing.T) {
t.SkipNow()
t.Parallel()
nvidiaSmiCommand := "nvidia-smi"
qFields, err := parseAutoQFields(nvidiaSmiCommand, nil)
if err != nil {
fmt.Printf("error: %v\n", err)
os.Exit(1)
}
fields := QFieldSliceToStringSlice(qFields)
fmt.Printf("Fields:\n\n%s\n", strings.Join(fields, "\n"))
}