-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package checks | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ethpandaops/panda-pulse/pkg/grafana" | ||
"github.com/ethpandaops/panda-pulse/pkg/grafana/mock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestELBlockHeightCheck_Run(t *testing.T) { | ||
failingResponse := &grafana.QueryResponse{ | ||
Results: grafana.QueryResults{ | ||
PandaPulse: grafana.QueryPandaPulse{ | ||
Frames: []grafana.QueryFrame{ | ||
{ | ||
Schema: grafana.QuerySchema{ | ||
Fields: []grafana.QueryField{ | ||
{ | ||
Labels: map[string]string{ | ||
"instance": "node1", | ||
"ingress_user": "user1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Data: grafana.QueryData{ | ||
Values: []interface{}{1.0}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
config Config | ||
mockResponse *grafana.QueryResponse | ||
mockError error | ||
expectedStatus Status | ||
expectError bool | ||
}{ | ||
{ | ||
name: "all nodes advancing", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: &grafana.QueryResponse{}, | ||
expectedStatus: StatusOK, | ||
}, | ||
{ | ||
name: "nodes not advancing", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: failingResponse, | ||
expectedStatus: StatusFail, | ||
}, | ||
{ | ||
name: "grafana error", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockError: assert.AnError, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockClient := mock.NewMockGrafanaClient(ctrl) | ||
mockClient.EXPECT().Query(gomock.Any(), gomock.Any()).Return(tt.mockResponse, tt.mockError) | ||
|
||
check := NewELBlockHeightCheck(mockClient) | ||
result, err := check.Run(context.Background(), tt.config) | ||
|
||
if tt.expectError { | ||
require.Error(t, err) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, tt.expectedStatus, result.Status) | ||
assert.NotEmpty(t, result.Description) | ||
assert.NotNil(t, result.Details) | ||
assert.Contains(t, result.Details, "query") | ||
}) | ||
} | ||
} | ||
|
||
func TestELBlockHeightCheck_Name(t *testing.T) { | ||
check := NewELBlockHeightCheck(nil) | ||
assert.Equal(t, "Block height not advancing", check.Name()) | ||
} | ||
|
||
func TestELBlockHeightCheck_Category(t *testing.T) { | ||
check := NewELBlockHeightCheck(nil) | ||
assert.Equal(t, CategorySync, check.Category()) | ||
} | ||
|
||
func TestELBlockHeightCheck_ClientType(t *testing.T) { | ||
check := NewELBlockHeightCheck(nil) | ||
assert.Equal(t, ClientTypeEL, check.ClientType()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package checks | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ethpandaops/panda-pulse/pkg/grafana" | ||
"github.com/ethpandaops/panda-pulse/pkg/grafana/mock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestELPeerCountCheck_Run(t *testing.T) { | ||
failingResponse := &grafana.QueryResponse{ | ||
Results: grafana.QueryResults{ | ||
PandaPulse: grafana.QueryPandaPulse{ | ||
Frames: []grafana.QueryFrame{ | ||
{ | ||
Schema: grafana.QuerySchema{ | ||
Fields: []grafana.QueryField{ | ||
{ | ||
Labels: map[string]string{ | ||
"instance": "node1", | ||
"network": "mainnet", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Data: grafana.QueryData{ | ||
Values: []interface{}{1.0}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
config Config | ||
mockResponse *grafana.QueryResponse | ||
mockError error | ||
expectedStatus Status | ||
expectError bool | ||
}{ | ||
{ | ||
name: "all nodes have sufficient peers", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: &grafana.QueryResponse{}, | ||
expectedStatus: StatusOK, | ||
}, | ||
{ | ||
name: "nodes with low peer count", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: failingResponse, | ||
expectedStatus: StatusFail, | ||
}, | ||
{ | ||
name: "grafana error", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockError: assert.AnError, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockClient := mock.NewMockGrafanaClient(ctrl) | ||
mockClient.EXPECT().Query(gomock.Any(), gomock.Any()).Return(tt.mockResponse, tt.mockError) | ||
|
||
check := NewELPeerCountCheck(mockClient) | ||
result, err := check.Run(context.Background(), tt.config) | ||
|
||
if tt.expectError { | ||
require.Error(t, err) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, tt.expectedStatus, result.Status) | ||
assert.NotEmpty(t, result.Description) | ||
assert.NotNil(t, result.Details) | ||
assert.Contains(t, result.Details, "query") | ||
}) | ||
} | ||
} | ||
|
||
func TestELPeerCountCheck_Name(t *testing.T) { | ||
check := NewELPeerCountCheck(nil) | ||
assert.Equal(t, "Low peer count", check.Name()) | ||
} | ||
|
||
func TestELPeerCountCheck_Category(t *testing.T) { | ||
check := NewELPeerCountCheck(nil) | ||
assert.Equal(t, CategorySync, check.Category()) | ||
} | ||
|
||
func TestELPeerCountCheck_ClientType(t *testing.T) { | ||
check := NewELPeerCountCheck(nil) | ||
assert.Equal(t, ClientTypeEL, check.ClientType()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package checks | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ethpandaops/panda-pulse/pkg/grafana" | ||
"github.com/ethpandaops/panda-pulse/pkg/grafana/mock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestELSyncCheck_Run(t *testing.T) { | ||
failingResponse := &grafana.QueryResponse{ | ||
Results: grafana.QueryResults{ | ||
PandaPulse: grafana.QueryPandaPulse{ | ||
Frames: []grafana.QueryFrame{ | ||
{ | ||
Schema: grafana.QuerySchema{ | ||
Fields: []grafana.QueryField{ | ||
{ | ||
Labels: map[string]string{ | ||
"instance": "node1", | ||
"network": "mainnet", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Data: grafana.QueryData{ | ||
Values: []interface{}{1.0}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
config Config | ||
mockResponse *grafana.QueryResponse | ||
mockError error | ||
expectedStatus Status | ||
expectError bool | ||
}{ | ||
{ | ||
name: "all nodes synced", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: &grafana.QueryResponse{}, | ||
expectedStatus: StatusOK, | ||
}, | ||
{ | ||
name: "nodes not syncing", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockResponse: failingResponse, | ||
expectedStatus: StatusFail, | ||
}, | ||
{ | ||
name: "grafana error", | ||
config: Config{ | ||
Network: "mainnet", | ||
ConsensusNode: "lighthouse", | ||
ExecutionNode: "geth", | ||
}, | ||
mockError: assert.AnError, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockClient := mock.NewMockGrafanaClient(ctrl) | ||
mockClient.EXPECT().Query(gomock.Any(), gomock.Any()).Return(tt.mockResponse, tt.mockError) | ||
|
||
check := NewELSyncCheck(mockClient) | ||
result, err := check.Run(context.Background(), tt.config) | ||
|
||
if tt.expectError { | ||
require.Error(t, err) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, tt.expectedStatus, result.Status) | ||
assert.NotEmpty(t, result.Description) | ||
assert.NotNil(t, result.Details) | ||
assert.Contains(t, result.Details, "query") | ||
}) | ||
} | ||
} | ||
|
||
func TestELSyncCheck_Name(t *testing.T) { | ||
check := NewELSyncCheck(nil) | ||
assert.Equal(t, "Node failing to sync", check.Name()) | ||
} | ||
|
||
func TestELSyncCheck_Category(t *testing.T) { | ||
check := NewELSyncCheck(nil) | ||
assert.Equal(t, CategorySync, check.Category()) | ||
} | ||
|
||
func TestELSyncCheck_ClientType(t *testing.T) { | ||
check := NewELSyncCheck(nil) | ||
assert.Equal(t, ClientTypeEL, check.ClientType()) | ||
} |