Skip to content

Commit

Permalink
🐛 Fix two bugs
Browse files Browse the repository at this point in the history
 - Fix a bug in unitest file
 - Fix a bug in golangci yaml file
  • Loading branch information
hrmhatef committed Aug 12, 2024
1 parent cd6fcd6 commit f932fe1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
run:
timeout: 5m
go: "1.19"
skip-files:
- "bindata.go"

linters:
disable-all: true
Expand Down Expand Up @@ -36,6 +34,8 @@ linters:
# - testpackage // Consider to adopt in the future

issues:
exclude-files:
- "bindata.go"
exclude-rules:
- source: "(noinspection|TODO)"
linters: [ godot ]
Expand All @@ -56,4 +56,4 @@ linters-settings:
- name: var-naming
disabled: true
stylecheck:
checks: ["*", "-ST1003"]
checks: ["*", "-ST1003"]
28 changes: 17 additions & 11 deletions cmd/faultdetector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
port = 8088
faultProofWindow = 1000
currentOutputIndex = 1
l1RpcApi = "https://rpc.notadegen.com/eth"
l1RpcApi = "https://rpc.ankr.com/eth"
l2RpcApi = "https://mainnet.optimism.io/"
faultDetectorStateMismatchMetricKey = "fault_detector_is_state_mismatch"
metricValue = "value"
Expand Down Expand Up @@ -86,21 +86,27 @@ func randTimestamp() (out uint64) {
return timestamp
}

func prepareHTTPServer(t *testing.T, ctx context.Context, logger log.Logger, config *config.Config, wg *sync.WaitGroup, erroChan chan error) *api.HTTPServer {
func prepareHTTPServer(ctx context.Context, logger log.Logger, config *config.Config, wg *sync.WaitGroup, erroChan chan error) *api.HTTPServer {
testServer := api.NewHTTPServer(ctx, logger, wg, config, erroChan)
return testServer
}

func prepareNotification(t *testing.T, ctx context.Context, logger log.Logger, config *config.Config) *notification.Notification {
func prepareNotification(ctx context.Context, logger log.Logger, config *config.Config) *notification.Notification {
slackNotificationClient.On(postMessageContextFnName).Return(channelID, "1234569.1000", nil)
testNotificationService := notification.GetNotification(ctx, logger, slackNotificationClient, config.Notification)
return testNotificationService
}

func prepareFaultDetector(t *testing.T, ctx context.Context, logger log.Logger, testNotificationService *notification.Notification, wg *sync.WaitGroup, reg *prometheus.Registry, config *config.Config, erroChan chan error, mock bool) *faultdetector.FaultDetector {
var fd *faultdetector.FaultDetector
func prepareFaultDetector(ctx context.Context, logger log.Logger, testNotificationService *notification.Notification, wg *sync.WaitGroup, reg *prometheus.Registry, config *config.Config, erroChan chan error, mock bool) *faultdetector.FaultDetector {
var (
fd *faultdetector.FaultDetector
err error
)
if !mock {
fd, _ = faultdetector.NewFaultDetector(ctx, logger, erroChan, wg, config.FaultDetectorConfig, reg, testNotificationService)
fd, err = faultdetector.NewFaultDetector(ctx, logger, erroChan, wg, config.FaultDetectorConfig, reg, testNotificationService)
if err != nil {
panic(err)
}
} else {
mx := new(sync.RWMutex)
metrics := faultdetector.NewFaultDetectorMetrics(reg)
Expand Down Expand Up @@ -143,7 +149,7 @@ func prepareFaultDetector(t *testing.T, ctx context.Context, logger log.Logger,
return fd
}

func prepareConfig(t *testing.T) *config.Config {
func prepareConfig() *config.Config {
serverPort, err := strconv.Atoi(fmt.Sprintf("%d", port))
if err != nil {
panic(err)
Expand Down Expand Up @@ -245,10 +251,10 @@ func TestMain_E2E(t *testing.T) {

errorChan := make(chan error)
registry := prometheus.NewRegistry()
testConfig := prepareConfig(&testing.T{})
testServer := prepareHTTPServer(&testing.T{}, ctx, logger, testConfig, &wg, errorChan)
testNotificationService := prepareNotification(&testing.T{}, ctx, logger, testConfig)
testFaultDetector := prepareFaultDetector(&testing.T{}, ctx, logger, testNotificationService, &wg, registry, testConfig, errorChan, tt.mock)
testConfig := prepareConfig()
testServer := prepareHTTPServer(ctx, logger, testConfig, &wg, errorChan)
testNotificationService := prepareNotification(ctx, logger, testConfig)
testFaultDetector := prepareFaultDetector(ctx, logger, testNotificationService, &wg, registry, testConfig, errorChan, tt.mock)

testServer.RegisterHandler("GET", "/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{Registry: registry, ProcessStartTime: time.Now()}))

Expand Down

0 comments on commit f932fe1

Please sign in to comment.