fix: resolve 8 staticcheck lint errors in test files

SA1029: use typed context key instead of string in main_test.go
S1039: remove unnecessary fmt.Sprintf in validation_test.go
SA4023: fix unreachable nil check on concrete error type
SA4006: fix unused variable assignments in stepca_test.go (4 occurrences)
SA4000: fix duplicate expression in ssh_test.go (BEGIN vs END CERTIFICATE)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shankar0123
2026-04-09 23:27:57 -04:00
parent 7382e5f03b
commit 370f856725
4 changed files with 17 additions and 17 deletions
+2 -1
View File
@@ -512,7 +512,8 @@ func TestMain_ContentTypeMiddleware(t *testing.T) {
// TestMain_ContextPropagation verifies context is propagated through middleware. // TestMain_ContextPropagation verifies context is propagated through middleware.
func TestMain_ContextPropagation(t *testing.T) { func TestMain_ContextPropagation(t *testing.T) {
testKey := "test-key" type contextKey string
testKey := contextKey("test-key")
testValue := "test-value" testValue := "test-value"
baseHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { baseHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+6 -7
View File
@@ -7,7 +7,6 @@ import (
"crypto/x509" "crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"fmt"
"strings" "strings"
"testing" "testing"
) )
@@ -522,7 +521,7 @@ func TestValidationError_ErrorMessage(t *testing.T) {
name: "error with field info", name: "error with field info",
err: ValidationError{ err: ValidationError{
Field: "test_field", Field: "test_field",
Message: fmt.Sprintf("test_field must be 10 characters or fewer"), Message: "test_field must be 10 characters or fewer",
}, },
wantMsg: "test_field must be 10 characters or fewer", wantMsg: "test_field must be 10 characters or fewer",
}, },
@@ -540,16 +539,16 @@ func TestValidationError_ErrorMessage(t *testing.T) {
// TestValidationError_IsError tests that ValidationError satisfies error interface. // TestValidationError_IsError tests that ValidationError satisfies error interface.
func TestValidationError_IsError(t *testing.T) { func TestValidationError_IsError(t *testing.T) {
var err error = ValidationError{ ve := ValidationError{
Field: "test", Field: "test",
Message: "test error", Message: "test error",
} }
if err == nil { // Assign to interface variable to verify it satisfies error
t.Error("ValidationError should satisfy error interface") var err error = ve
} _ = err
msg := err.Error() msg := ve.Error()
if msg != "test error" { if msg != "test error" {
t.Errorf("Expected error message 'test error', got %q", msg) t.Errorf("Expected error message 'test error', got %q", msg)
} }
@@ -376,7 +376,7 @@ func TestGenerateProvisionerTokenEphemeralKey(t *testing.T) {
ProvisionerName: "test-provisioner", ProvisionerName: "test-provisioner",
// No ProvisionerKeyPath — forces ephemeral key generation // No ProvisionerKeyPath — forces ephemeral key generation
} }
connector := stepca.New(config, logger) _ = stepca.New(config, logger) // verify constructor doesn't panic
// This should NOT panic and should return a non-empty token // This should NOT panic and should return a non-empty token
_, csrPEM, _ := generateStepCATestCSR("test.example.com") _, csrPEM, _ := generateStepCATestCSR("test.example.com")
@@ -405,7 +405,7 @@ func TestGenerateProvisionerTokenEphemeralKey(t *testing.T) {
defer srv.Close() defer srv.Close()
config.CAURL = srv.URL config.CAURL = srv.URL
connector = stepca.New(config, logger) connector := stepca.New(config, logger)
result, err := connector.IssueCertificate(ctx, req) result, err := connector.IssueCertificate(ctx, req)
if err != nil { if err != nil {
@@ -427,7 +427,7 @@ func TestParseSignResponse_SimpleFormat(t *testing.T) {
CAURL: "https://ca.example.com", CAURL: "https://ca.example.com",
ProvisionerName: "test-provisioner", ProvisionerName: "test-provisioner",
} }
connector := stepca.New(config, logger) _ = stepca.New(config, logger) // verify constructor doesn't panic
// Test the simple crt/ca response format // Test the simple crt/ca response format
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -447,7 +447,7 @@ func TestParseSignResponse_SimpleFormat(t *testing.T) {
defer srv.Close() defer srv.Close()
config.CAURL = srv.URL config.CAURL = srv.URL
connector = stepca.New(config, logger) connector := stepca.New(config, logger)
_, csrPEM, _ := generateStepCATestCSR("test.example.com") _, csrPEM, _ := generateStepCATestCSR("test.example.com")
req := issuer.IssuanceRequest{ req := issuer.IssuanceRequest{
@@ -478,7 +478,7 @@ func TestParseSignResponse_StructuredFormat(t *testing.T) {
CAURL: "https://ca.example.com", CAURL: "https://ca.example.com",
ProvisionerName: "test-provisioner", ProvisionerName: "test-provisioner",
} }
connector := stepca.New(config, logger) _ = stepca.New(config, logger) // verify constructor doesn't panic
// Test the structured response format // Test the structured response format
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -501,7 +501,7 @@ func TestParseSignResponse_StructuredFormat(t *testing.T) {
defer srv.Close() defer srv.Close()
config.CAURL = srv.URL config.CAURL = srv.URL
connector = stepca.New(config, logger) connector := stepca.New(config, logger)
_, csrPEM, _ := generateStepCATestCSR("test.example.com") _, csrPEM, _ := generateStepCATestCSR("test.example.com")
req := issuer.IssuanceRequest{ req := issuer.IssuanceRequest{
@@ -792,7 +792,7 @@ func TestParseSignResponse_CertChainFormat(t *testing.T) {
CAURL: "https://ca.example.com", CAURL: "https://ca.example.com",
ProvisionerName: "test-provisioner", ProvisionerName: "test-provisioner",
} }
connector := stepca.New(config, logger) _ = stepca.New(config, logger) // verify constructor doesn't panic
// Test the certChainPEM array response format (multiple certs in array) // Test the certChainPEM array response format (multiple certs in array)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -818,7 +818,7 @@ func TestParseSignResponse_CertChainFormat(t *testing.T) {
defer srv.Close() defer srv.Close()
config.CAURL = srv.URL config.CAURL = srv.URL
connector = stepca.New(config, logger) connector := stepca.New(config, logger)
_, csrPEM, _ := generateStepCATestCSR("test.example.com") _, csrPEM, _ := generateStepCATestCSR("test.example.com")
req := issuer.IssuanceRequest{ req := issuer.IssuanceRequest{
+1 -1
View File
@@ -760,7 +760,7 @@ func TestDeployCertificate_FullChainMode(t *testing.T) {
} }
certData := string(certWriteCall.Data) certData := string(certWriteCall.Data)
if !containsString(certData, "BEGIN CERTIFICATE") || !containsString(certData, "BEGIN CERTIFICATE") { if !containsString(certData, "BEGIN CERTIFICATE") || !containsString(certData, "END CERTIFICATE") {
t.Errorf("cert data should contain combined cert and chain") t.Errorf("cert data should contain combined cert and chain")
} }