mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-14 20:09:04 +00:00
fix: use tagged switch statements to satisfy staticcheck QF1002
Convert `switch { case r.URL.Path == ... }` to `switch r.URL.Path { ... }`
in Vault and DigiCert connector tests to pass golangci-lint CI.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -241,11 +241,11 @@ func TestDigiCertConnector(t *testing.T) {
|
|||||||
pemBundle := testCertPEM + testChainPEM
|
pemBundle := testCertPEM + testChainPEM
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch r.URL.Path {
|
||||||
case r.URL.Path == "/order/certificate/99001":
|
case "/order/certificate/99001":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(`{"id":99001,"status":"issued","certificate":{"id":88001,"common_name":"app.example.com"}}`))
|
w.Write([]byte(`{"id":99001,"status":"issued","certificate":{"id":88001,"common_name":"app.example.com"}}`))
|
||||||
case r.URL.Path == "/certificate/88001/download/format/pem_all":
|
case "/certificate/88001/download/format/pem_all":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(pemBundle))
|
w.Write([]byte(pemBundle))
|
||||||
default:
|
default:
|
||||||
@@ -431,11 +431,11 @@ func TestDigiCertConnector(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("GetOrderStatus_DownloadError", func(t *testing.T) {
|
t.Run("GetOrderStatus_DownloadError", func(t *testing.T) {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch r.URL.Path {
|
||||||
case r.URL.Path == "/order/certificate/99004":
|
case "/order/certificate/99004":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(`{"id":99004,"status":"issued","certificate":{"id":88004}}`))
|
w.Write([]byte(`{"id":99004,"status":"issued","certificate":{"id":88004}}`))
|
||||||
case r.URL.Path == "/certificate/88004/download/format/pem_all":
|
case "/certificate/88004/download/format/pem_all":
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(`{"errors":["internal server error"]}`))
|
w.Write([]byte(`{"errors":["internal server error"]}`))
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -317,10 +317,10 @@ func TestVaultConnector(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("RevokeCertificate_Success", func(t *testing.T) {
|
t.Run("RevokeCertificate_Success", func(t *testing.T) {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch r.URL.Path {
|
||||||
case r.URL.Path == "/v1/sys/health":
|
case "/v1/sys/health":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
case r.URL.Path == "/v1/pki/revoke":
|
case "/v1/pki/revoke":
|
||||||
// Verify token
|
// Verify token
|
||||||
if r.Header.Get("X-Vault-Token") == "" {
|
if r.Header.Get("X-Vault-Token") == "" {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
@@ -356,10 +356,10 @@ func TestVaultConnector(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("RevokeCertificate_ServerError", func(t *testing.T) {
|
t.Run("RevokeCertificate_ServerError", func(t *testing.T) {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch r.URL.Path {
|
||||||
case r.URL.Path == "/v1/sys/health":
|
case "/v1/sys/health":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
case r.URL.Path == "/v1/pki/revoke":
|
case "/v1/pki/revoke":
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte(`{"errors":["serial not found"]}`))
|
w.Write([]byte(`{"errors":["serial not found"]}`))
|
||||||
default:
|
default:
|
||||||
@@ -390,8 +390,8 @@ func TestVaultConnector(t *testing.T) {
|
|||||||
expectedPEM := "-----BEGIN CERTIFICATE-----\nTESTCA\n-----END CERTIFICATE-----\n"
|
expectedPEM := "-----BEGIN CERTIFICATE-----\nTESTCA\n-----END CERTIFICATE-----\n"
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch r.URL.Path {
|
||||||
case r.URL.Path == "/v1/pki/ca/pem":
|
case "/v1/pki/ca/pem":
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(expectedPEM))
|
w.Write([]byte(expectedPEM))
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user