Skip to content

Commit becbad3

Browse files
committed
fix golangci findings
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent 00b13ac commit becbad3

File tree

10 files changed

+17
-13
lines changed

10 files changed

+17
-13
lines changed

api/cluster_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func TestClusterSummaryUnmarshalJSON(t *testing.T) {
4343
FailureCount: 4,
4444
SuccessCount: 1,
4545
Reports: []*ReportSummary{
46-
&ReportSummary{
46+
{
4747
ID: "exampleReport1",
4848
Package: "examplePackage.ID.1",
4949
Cluster: "exampleCluster",
5050
Timestamp: Time{Time: ts},
5151
FailureCount: 2,
5252
SuccessCount: 1,
5353
},
54-
&ReportSummary{
54+
{
5555
ID: "exampleReport2",
5656
Package: "examplePackage.ID.2",
5757
Cluster: "exampleCluster",

pkg/client/client_api_token.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"path/filepath"
1111
"time"
1212

13+
"k8s.io/client-go/transport"
14+
1315
"github.com/jetstack/preflight/api"
1416
"github.com/jetstack/preflight/pkg/version"
15-
"k8s.io/client-go/transport"
1617
)
1718

1819
type (

pkg/client/client_oauth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (c *OAuthClient) renewAccessToken(ctx context.Context) error {
189189
if err != nil {
190190
return errors.WithStack(err)
191191
}
192-
req.Header.Add("content-type", "application/x-www-form-urlencoded")
192+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
193193
req.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
194194

195195
res, err := http.DefaultClient.Do(req)

pkg/datagatherer/k8s/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestNewDiscoveryClient_InferredKubeconfig(t *testing.T) {
5454
}
5555

5656
func writeConfigToFile(t *testing.T, cfg clientcmdapi.Config) string {
57-
f, err := os.CreateTemp("", "testcase-*")
57+
f, err := os.CreateTemp(t.TempDir(), "testcase-*")
5858
if err != nil {
5959
t.Fatal(err)
6060
}

pkg/datagatherer/k8s/fieldfilter_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/json"
55
"testing"
66

7-
"github.com/jetstack/preflight/pkg/testutil"
87
"github.com/stretchr/testify/assert"
98
"github.com/stretchr/testify/require"
109
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10+
11+
"github.com/jetstack/preflight/pkg/testutil"
1112
)
1213

1314
func TestSelect(t *testing.T) {

pkg/echo/echo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestEchoServerRequestResponse(t *testing.T) {
3030
},
3131
DataGatherTime: time.Now(),
3232
DataReadings: []*api.DataReading{
33-
&api.DataReading{
33+
{
3434
ClusterID: "test_suite_cluster",
3535
DataGatherer: "dummy",
3636
Timestamp: api.Time{Time: time.Now()},

pkg/logs/logs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
"k8s.io/component-base/featuregate"
1414
"k8s.io/component-base/logs"
1515
logsapi "k8s.io/component-base/logs/api/v1"
16-
_ "k8s.io/component-base/logs/json/register"
1716
"k8s.io/klog/v2"
1817
ctrlruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
18+
19+
_ "k8s.io/component-base/logs/json/register"
1920
)
2021

2122
// venafi-kubernetes-agent follows [Kubernetes Logging Conventions] and writes

pkg/logs/logs_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
"testing"
1616
"time"
1717

18-
_ "github.com/Venafi/vcert/v5"
1918
"github.com/spf13/pflag"
2019
"github.com/stretchr/testify/assert"
2120
"github.com/stretchr/testify/require"
2221
"k8s.io/klog/v2"
2322

2423
"github.com/jetstack/preflight/pkg/logs"
24+
25+
_ "github.com/Venafi/vcert/v5"
2526
)
2627

2728
// TestLogs demonstrates how the logging flags affect the logging output.

pkg/testutil/envtest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ func FakeVenafiCloud(t *testing.T) (_ *httptest.Server, _ *x509.Certificate, set
200200
}
201201

202202
accessToken := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
203-
apiKey := r.Header.Get("tppl-api-key")
203+
apiKey := r.Header.Get("Tppl-Api-Key")
204204
if accessToken != "VALID_ACCESS_TOKEN" && apiKey != "VALID_API_KEY" {
205205
w.WriteHeader(http.StatusUnauthorized)
206-
w.Write([]byte(`{"error":"expected header 'Authorization: Bearer VALID_ACCESS_TOKEN' or 'tppl-api-key: VALID_API_KEY', but got Authorization=` + r.Header.Get("Authorization") + ` and tppl-api-key=` + r.Header.Get("tppl-api-key")))
206+
w.Write([]byte(`{"error":"expected header 'Authorization: Bearer VALID_ACCESS_TOKEN' or 'tppl-api-key: VALID_API_KEY', but got Authorization=` + r.Header.Get("Authorization") + ` and tppl-api-key=` + r.Header.Get("Tppl-Api-Key")))
207207
return
208208
}
209209
if r.URL.Path == "/v1/tlspk/upload/clusterdata/no" {

pkg/testutil/undent.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func Undent(s string) string {
6868
}
6969

7070
curLineIndent := 0 // Number of tabs or spaces in the current line.
71-
for pos := 0; pos < len(s); pos++ {
71+
for pos := range s {
7272
if s[pos] == '\n' {
7373
if pos+1 < len(s) {
7474
lineOffsets = append(lineOffsets, pos+1)
@@ -102,7 +102,7 @@ func Undent(s string) string {
102102
// Extract each line without indentation.
103103
out := make([]byte, 0, len(s)-(indentsPerLine*indentedLinesCnt))
104104

105-
for line := 0; line < len(lineOffsets); line++ {
105+
for line := range lineOffsets {
106106
first := lineOffsets[line]
107107

108108
// Index of the last character of the line. It is often the '\n'

0 commit comments

Comments
 (0)