Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcauchi committed Oct 3, 2024
1 parent 09a5785 commit 94ed139
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/client/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/go-resty/resty/v2"

"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
)

Expand Down
26 changes: 20 additions & 6 deletions lib/client/loki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -17,7 +18,7 @@ func TestLokiClient_SuccessfulQuery(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/loki/api/v1/query_range", r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{
_, err := w.Write([]byte(`{
"data": {
"result": [
{
Expand All @@ -30,6 +31,7 @@ func TestLokiClient_SuccessfulQuery(t *testing.T) {
]
}
}`))
assert.NoError(t, err)
}))
defer mockServer.Close()

Expand Down Expand Up @@ -87,16 +89,22 @@ func TestLokiClient_AuthenticationFailure(t *testing.T) {
logEntries, err := lokiClient.QueryLogs(context.Background())
assert.Nil(t, logEntries)
assert.Error(t, err)
assert.IsType(t, &LokiAPIError{}, err)
assert.Equal(t, http.StatusUnauthorized, err.(*LokiAPIError).StatusCode)
var lokiErr *LokiAPIError
if errors.As(err, &lokiErr) {
assert.Equal(t, http.StatusUnauthorized, lokiErr.StatusCode)
} else {
t.Fatalf("Expected LokiAPIError, got %v", err)
}
}

func TestLokiClient_InternalServerError(t *testing.T) {
// Create a mock Loki server
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/loki/api/v1/query_range", r.URL.Path)
w.WriteHeader(http.StatusInternalServerError) // Simulate server error
w.Write([]byte(`{"message": "internal server error"}`)) // Error message in the response body
w.WriteHeader(http.StatusInternalServerError) // Simulate server error
_, err := w.Write([]byte(`{"message": "internal server error"}`)) // Error message in the response body
assert.NoError(t, err)
}))
defer mockServer.Close()

Expand All @@ -117,8 +125,13 @@ func TestLokiClient_InternalServerError(t *testing.T) {
logEntries, err := lokiClient.QueryLogs(context.Background())
assert.Nil(t, logEntries)
assert.Error(t, err)
assert.IsType(t, &LokiAPIError{}, err)
assert.Equal(t, http.StatusInternalServerError, err.(*LokiAPIError).StatusCode)
var lokiErr *LokiAPIError
if errors.As(err, &lokiErr) {
assert.Equal(t, http.StatusInternalServerError, lokiErr.StatusCode)
} else {
t.Fatalf("Expected LokiAPIError, got %v", err)
}
}

func TestLokiClient_DebugMode(t *testing.T) {
Expand All @@ -130,7 +143,7 @@ func TestLokiClient_DebugMode(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/loki/api/v1/query_range", r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{
_, err := w.Write([]byte(`{
"data": {
"result": [
{
Expand All @@ -143,6 +156,7 @@ func TestLokiClient_DebugMode(t *testing.T) {
]
}
}`))
assert.NoError(t, err)
}))
defer mockServer.Close()

Expand Down

0 comments on commit 94ed139

Please sign in to comment.