From 4133aa1f3e1c1b9dc86196f1dd82db3630682041 Mon Sep 17 00:00:00 2001 From: nscuro Date: Sun, 4 Jun 2023 14:22:57 +0200 Subject: [PATCH] chore: delete unused code Signed-off-by: nscuro --- internal/opa/client.go | 52 ------------------------------------- internal/opa/client_test.go | 17 +++--------- 2 files changed, 4 insertions(+), 65 deletions(-) diff --git a/internal/opa/client.go b/internal/opa/client.go index e490487..6c9a1a7 100644 --- a/internal/opa/client.go +++ b/internal/opa/client.go @@ -92,54 +92,6 @@ func (c Client) Decision(ctx context.Context, decisionPath string, input any, re return } -// Health checks whether OPA is operational. -// See: https://www.openpolicyagent.org/docs/latest/rest-api/#health-api -func (c Client) Health(ctx context.Context) (err error) { - healthURL, err := c.baseURL.Parse(path.Join("/health")) - if err != nil { - err = fmt.Errorf("failed to parse request url: %w", err) - return - } - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL.String(), nil) - if err != nil { - err = fmt.Errorf("failed to create request: %w", err) - return - } - - req.Header.Set("Accept", "application/json") - req.Header.Set("User-Agent", "dtapac") - - res, err := c.httpClient.Do(req) - if err != nil { - err = fmt.Errorf("failed to send request: %w", err) - return - } - defer res.Body.Close() - - if res.StatusCode == http.StatusOK { - return - } else if res.StatusCode == http.StatusInternalServerError { - var healthRes healthResponse - err = json.NewDecoder(res.Body).Decode(&healthRes) - if err != nil { - err = fmt.Errorf("failed to decode response: %w", err) - return - } - - if healthRes.Error == "" { - err = fmt.Errorf("response status is %d, but no error field was returned", http.StatusInternalServerError) - return - } - - err = errors.New(healthRes.Error) - return - } - - err = fmt.Errorf("unexpected response code: %d", res.StatusCode) - return -} - type decisionRequest struct { Input any `json:"input"` } @@ -147,7 +99,3 @@ type decisionRequest struct { type decisionResponse struct { Result *json.RawMessage `json:"result"` } - -type healthResponse struct { - Error string `json:"error"` -} diff --git a/internal/opa/client_test.go b/internal/opa/client_test.go index e3c63fe..6ba61d4 100644 --- a/internal/opa/client_test.go +++ b/internal/opa/client_test.go @@ -4,12 +4,13 @@ import ( "bytes" "context" "fmt" - "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" "net/http" "os" "testing" + + "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) func TestClient_Decision(t *testing.T) { @@ -46,16 +47,6 @@ func TestClient_Decision(t *testing.T) { }) } -func TestClient_Health(t *testing.T) { - opaURL := setupOPA(t) - - client, err := NewClient(opaURL) - require.NoError(t, err) - - err = client.Health(context.TODO()) - require.NoError(t, err) -} - func setupOPA(t *testing.T) string { req := testcontainers.ContainerRequest{ Image: "openpolicyagent/opa:0.40.0-rootless",