From 2aa69779d7a6ef8d72ec09b7f06fea0538adf600 Mon Sep 17 00:00:00 2001 From: Tymur Khrushchov Date: Wed, 6 Nov 2024 18:51:13 +0100 Subject: [PATCH] ci changes --- .github/workflows/checks.yml | 22 +++++++++++++++++++-- .golangci.yaml | 1 + adapters/database/service_test.go | 21 ++++++++++---------- httpserver/handler.go | 4 ---- httpserver/handler_test.go | 32 +------------------------------ 5 files changed, 33 insertions(+), 47 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index f14fdde..c659cda 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -10,6 +10,21 @@ jobs: test: name: Test runs-on: ubuntu-latest + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 steps: - name: Set up Go uses: actions/setup-go@v3 @@ -20,6 +35,9 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Run migrations + run: for file in schema/*.sql; do psql "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -f $file; done + - name: Run unit tests and generate the coverage report run: make test-race @@ -30,7 +48,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: ^1.21 + go-version: ^1.22 id: go - name: Check out code into the Go module directory @@ -40,7 +58,7 @@ jobs: run: go install mvdan.cc/gofumpt@v0.4.0 - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.2 + run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1 - name: Install golangci-lint run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 diff --git a/.golangci.yaml b/.golangci.yaml index 2dd2c60..5dcb09b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -31,6 +31,7 @@ linters: - prealloc - whitespace - musttag + - mnd # # Disabled because of generics: diff --git a/adapters/database/service_test.go b/adapters/database/service_test.go index 7acca77..4702d83 100644 --- a/adapters/database/service_test.go +++ b/adapters/database/service_test.go @@ -2,9 +2,10 @@ package database import ( "context" - "fmt" "net" "testing" + + "github.com/stretchr/testify/require" ) func TestGetBuilder(t *testing.T) { @@ -14,25 +15,25 @@ func TestGetBuilder(t *testing.T) { } t.Run("GetBuilder2", func(t *testing.T) { t.Run("should return a builder", func(t *testing.T) { + _, err := serv.DB.Exec("INSERT INTO public.builders (name, ip_address, is_active, created_at, updated_at) VALUES ('flashbots-builder', '192.168.1.1', true, '2024-10-11 13:05:56.845615 +00:00', '2024-10-11 13:05:56.845615 +00:00');") + require.NoError(t, err) whitelist, err := serv.GetBuilderByIP(net.ParseIP("192.168.1.1")) - if err != nil { - t.Errorf("GetIPWhitelistByIP() = %v; want nil", err) - } - fmt.Println(whitelist) + require.NoError(t, err) + require.Equal(t, whitelist.Name, "flashbots-builder") }) t.Run("get all active builders", func(t *testing.T) { whitelist, err := serv.GetActiveBuildersWithServiceCredentials(context.Background()) - if err != nil { - t.Errorf("GetIPWhitelistByIP() = %v; want nil", err) - } - fmt.Println(whitelist) + require.Nil(t, err) + require.Lenf(t, whitelist, 1, "expected 1 builder, got %d", len(whitelist)) + require.Equal(t, whitelist[0].Builder.Name, "flashbots-builder") }) t.Run("get all active measurements", func(t *testing.T) { whitelist, err := serv.GetActiveMeasurements(context.Background()) if err != nil { t.Errorf("GetIPWhitelistByIP() = %v; want nil", err) } - fmt.Println(whitelist) + require.Len(t, whitelist, 0) + // fmt.Println(whitelist) }) }) } diff --git a/httpserver/handler.go b/httpserver/handler.go index b92d1cc..8f3d007 100644 --- a/httpserver/handler.go +++ b/httpserver/handler.go @@ -39,7 +39,3 @@ func (srv *Server) handleTestPanic(w http.ResponseWriter, r *http.Request) { panic("foo") // w.WriteHeader(http.StatusOK) } - -// -// BuilderConfigHub API: https://www.notion.so/flashbots/BuilderConfigHub-1076b4a0d8768074bcdcd1c06c26ec87?pvs=4#10a6b4a0d87680fd81e0cad9bac3b8c5 -// diff --git a/httpserver/handler_test.go b/httpserver/handler_test.go index 6408261..0ccdbb3 100644 --- a/httpserver/handler_test.go +++ b/httpserver/handler_test.go @@ -1,7 +1,6 @@ package httpserver import ( - "bytes" "io" "net/http" "net/http/httptest" @@ -17,6 +16,7 @@ import ( var testServerConfig = &HTTPServerConfig{ Log: getTestLogger(), } +var _ = testServerConfig func getTestLogger() *httplog.Logger { return common.SetupLogger(&common.LoggingOpts{ @@ -99,33 +99,3 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { require.Equal(t, http.StatusOK, resp.StatusCode, "Healthcheck must return `Ok` after undraining") } } - -func Test_Handlers_BuilderConfigHub(t *testing.T) { - routes := []struct { - method string - path string - payload []byte - }{ - // BuilderConfigHub API: https://www.notion.so/flashbots/BuilderConfigHub-1076b4a0d8768074bcdcd1c06c26ec87?pvs=4#10a6b4a0d87680fd81e0cad9bac3b8c5 - {http.MethodGet, "/api/l1-builder/v1/measurements", nil}, - {http.MethodGet, "/api/l1-builder/v1/configuration", nil}, - {http.MethodGet, "/api/l1-builder/v1/builders", nil}, - {http.MethodPost, "/api/l1-builder/v1/register_credentials/rbuilder", []byte(`{"var1":"foo"}`)}, - } - - srv, err := NewHTTPServer(testServerConfig, ports.NewBuilderHubHandler(nil, getTestLogger())) - require.NoError(t, err) - - for _, r := range routes { - var payload io.Reader - if r.payload != nil { - payload = bytes.NewReader(r.payload) - } - req, err := http.NewRequest(r.method, r.path, payload) - require.NoError(t, err) - - rr := httptest.NewRecorder() - srv.getRouter().ServeHTTP(rr, req) - require.Equal(t, http.StatusOK, rr.Code) - } -}