diff --git a/.golangci.yml b/.golangci.yml index b7f94c6..c41e523 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,6 +59,7 @@ linters-settings: - github.com/stretchr/testify - github.com/slok/go-http-metrics - github.com/purini-to/zapmw + - github.com/caitlinelfring/go-env-default issues: max-same-issues: 0 # unlimited diff --git a/go.mod b/go.mod index 5eebdc0..af1105c 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21 require ( github.com/Shopify/toxiproxy v2.1.4+incompatible + github.com/caitlinelfring/go-env-default v1.1.0 github.com/ethereum/go-ethereum v1.13.5 github.com/gorilla/mux v1.8.1 github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f diff --git a/go.sum b/go.sum index 2e2b733..3bdbeae 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWso github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/caitlinelfring/go-env-default v1.1.0 h1:bhDfXmUolvcIGfQCX8qevQX8wxC54NGz0aimoUnhvDM= +github.com/caitlinelfring/go-env-default v1.1.0/go.mod h1:tESXPr8zFPP/cRy3cwxrHBmjJIf2A1x/o4C9CET2rEk= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/proxy/healthchecker_test.go b/internal/proxy/healthchecker_test.go index 9593763..803d7c5 100644 --- a/internal/proxy/healthchecker_test.go +++ b/internal/proxy/healthchecker_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/caitlinelfring/go-env-default" "github.com/stretchr/testify/assert" "go.uber.org/zap" ) @@ -22,7 +23,7 @@ func TestBasicHealthchecker(t *testing.T) { defer cancel() healtcheckConfig := RPCHealthcheckerConfig{ - URL: "https://cloudflare-eth.com", + URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"), Interval: 1 * time.Second, Timeout: 2 * time.Second, FailureThreshold: 1, @@ -48,7 +49,7 @@ func TestBasicHealthchecker(t *testing.T) { func TestGasLeftCall(t *testing.T) { client := &http.Client{} - url := "https://cloudflare-eth.com" + url := env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com") result, err := performGasLeftCall(context.TODO(), client, url) assert.Nil(t, err) diff --git a/internal/proxy/manager_test.go b/internal/proxy/manager_test.go index b009157..13cf1a2 100644 --- a/internal/proxy/manager_test.go +++ b/internal/proxy/manager_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/caitlinelfring/go-env-default" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" ) @@ -18,7 +19,7 @@ func TestHealthcheckManager(t *testing.T) { Name: "Primary", Connection: TargetConfigConnection{ HTTP: TargetConnectionHTTP{ - URL: "https://cloudflare-eth.com", + URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"), }, }, }, @@ -26,7 +27,7 @@ func TestHealthcheckManager(t *testing.T) { Name: "StandBy", Connection: TargetConfigConnection{ HTTP: TargetConnectionHTTP{ - URL: "https://cloudflare-eth.com", + URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://eth.public-rpc.com"), }, }, }, @@ -65,7 +66,7 @@ func TestGetNextHealthyTargetIndexExcluding(t *testing.T) { Name: "Primary", Connection: TargetConfigConnection{ HTTP: TargetConnectionHTTP{ - URL: "https://cloudflare-eth.com", + URL: env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com"), }, }, }, diff --git a/internal/rpcgateway/rpcgateway_test.go b/internal/rpcgateway/rpcgateway_test.go index b8f5f8a..6945fa6 100644 --- a/internal/rpcgateway/rpcgateway_test.go +++ b/internal/rpcgateway/rpcgateway_test.go @@ -11,6 +11,7 @@ import ( "testing" toxiproxy "github.com/Shopify/toxiproxy/client" + "github.com/caitlinelfring/go-env-default" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "go.uber.org/zap" @@ -77,7 +78,7 @@ func TestRpcGatewayFailover(t *testing.T) { err := toxiClient.ResetState() assert.Nil(t, err) - proxy, err := toxiClient.CreateProxy("cloudflare", "0.0.0.0:9991", ts.URL[7:]) + proxy, err := toxiClient.CreateProxy("primary", "0.0.0.0:9991", ts.URL[7:]) assert.Nil(t, err) _, err = proxy.AddToxic("latency_down", "latency", "downstream", 1.0, toxiproxy.Attributes{ @@ -92,7 +93,7 @@ func TestRpcGatewayFailover(t *testing.T) { // config string var tpl bytes.Buffer - tu := TestURL{"http://0.0.0.0:9991", "https://cloudflare-eth.com"} + tu := TestURL{"http://0.0.0.0:9991", env.GetDefault("RPC_GATEWAY_NODE_URL_1", "https://cloudflare-eth.com")} tmpl, err := template.New("test").Parse(rpcGatewayConfig) assert.Nil(t, err)