Debian Codegraph @

cmd/mdatagen/internal/lint_test.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestFormatIdentifier(t *testing.T) {
13 tests := []struct {
14 input string
15 want string
16 exported bool
17 wantErr string
18 }{
19 // Unexported.
20 {input: "max.cpu", want: "maxCPU"},
21 {input: "max.foo", want: "maxFoo"},
22 {input: "cpu.utilization", want: "cpuUtilization"},
23 {input: "cpu", want: "cpu"},
24 {input: "max.ip.addr", want: "maxIPAddr"},
25 {input: "some_metric", want: "someMetric"},
26 {input: "some-metric", want: "someMetric"},
27 {input: "Upper.Case", want: "upperCase"},
28 {input: "max.ip6", want: "maxIP6"},
29 {input: "max.ip6.idle", want: "maxIP6Idle"},
30 {input: "node_netstat_IpExt_OutOctets", want: "nodeNetstatIPExtOutOctets"},
31
32 // Exported.
33 {input: "cpu.state", want: "CPUState", exported: true},
34
35 // Errors
36 {input: "", want: "", wantErr: "string cannot be empty"},
37 }
38 for _, tt := range tests {
39 t.Run(tt.input, func(t *testing.T) {
40 got, err := FormatIdentifier(tt.input, tt.exported)
41
42 if tt.wantErr != "" {
43 require.EqualError(t, err, tt.wantErr)
44 } else {
45 require.NoError(t, err)
46 require.Equal(t, tt.want, got)
47 }
48 })
49 }
50 }