Skip to content

Commit

Permalink
core/web: simplify *TestApplication.NewHTTPClient() (#10957)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 17, 2023
1 parent ef4240f commit 0af1c02
Show file tree
Hide file tree
Showing 33 changed files with 106 additions and 102 deletions.
2 changes: 1 addition & 1 deletion core/cmd/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestRendererTable_RenderConfigurationV2(t *testing.T) {
app := cltest.NewApplicationEVMDisabled(t)
wantUser, wantEffective := app.Config.ConfigTOML()
require.NoError(t, app.Start(testutils.Context(t)))
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

t.Run("effective", func(t *testing.T) {
resp, cleanup := client.Get("/v2/config/v2")
Expand Down
16 changes: 10 additions & 6 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ type User struct {
func (ta *TestApplication) NewHTTPClient(user *User) HTTPClientCleaner {
ta.t.Helper()

if user == nil {
user = &User{}
}

if user.Email == "" {
user.Email = fmt.Sprintf("%[email protected]", uuid.New())
}
Expand Down Expand Up @@ -647,7 +651,7 @@ func (ta *TestApplication) NewClientOpts() cmd.ClientOpts {

// NewShellAndRenderer creates a new cmd.Shell for the test application
func (ta *TestApplication) NewShellAndRenderer() (*cmd.Shell, *RendererMock) {
hc := ta.NewHTTPClient(&User{})
hc := ta.NewHTTPClient(nil)
r := &RendererMock{}
lggr := logger.TestLogger(ta.t)
client := &cmd.Shell{
Expand Down Expand Up @@ -809,7 +813,7 @@ func ParseJSONAPIResponseMetaCount(input []byte) (int, error) {
func CreateJobViaWeb(t testing.TB, app *TestApplication, request []byte) job.Job {
t.Helper()

client := app.NewHTTPClient(&User{})
client := app.NewHTTPClient(nil)
resp, cleanup := client.Post("/v2/jobs", bytes.NewBuffer(request))
defer cleanup()
AssertServerResponse(t, resp, http.StatusOK)
Expand All @@ -823,7 +827,7 @@ func CreateJobViaWeb(t testing.TB, app *TestApplication, request []byte) job.Job
func CreateJobViaWeb2(t testing.TB, app *TestApplication, spec string) webpresenters.JobResource {
t.Helper()

client := app.NewHTTPClient(&User{})
client := app.NewHTTPClient(nil)
resp, cleanup := client.Post("/v2/jobs", bytes.NewBufferString(spec))
defer cleanup()
AssertServerResponse(t, resp, http.StatusOK)
Expand All @@ -837,7 +841,7 @@ func CreateJobViaWeb2(t testing.TB, app *TestApplication, spec string) webpresen
func DeleteJobViaWeb(t testing.TB, app *TestApplication, jobID int32) {
t.Helper()

client := app.NewHTTPClient(&User{})
client := app.NewHTTPClient(nil)
resp, cleanup := client.Delete(fmt.Sprintf("/v2/jobs/%v", jobID))
defer cleanup()
AssertServerResponse(t, resp, http.StatusNoContent)
Expand Down Expand Up @@ -886,7 +890,7 @@ func CreateJobRunViaUser(
t.Helper()

bodyBuf := bytes.NewBufferString(body)
client := app.NewHTTPClient(&User{})
client := app.NewHTTPClient(nil)
resp, cleanup := client.Post("/v2/jobs/"+jobID.String()+"/runs", bodyBuf)
defer cleanup()
AssertServerResponse(t, resp, 200)
Expand All @@ -905,7 +909,7 @@ func CreateExternalInitiatorViaWeb(
) *webpresenters.ExternalInitiatorAuthentication {
t.Helper()

client := app.NewHTTPClient(&User{})
client := app.NewHTTPClient(nil)
resp, cleanup := client.Post(
"/v2/external_initiators",
bytes.NewBufferString(payload),
Expand Down
4 changes: 2 additions & 2 deletions core/services/job/runner_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ func TestRunner_Success_Callback_AsyncJob(t *testing.T) {
{
url, err := url.Parse(responseURL)
require.NoError(t, err)
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)
body := strings.NewReader(`{"value": {"data":{"result":"123.45"}}}`)
response, cleanup := client.Patch(url.Path, body)
defer cleanup()
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func TestRunner_Error_Callback_AsyncJob(t *testing.T) {
{
url, err := url.Parse(responseURL)
require.NoError(t, err)
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)
body := strings.NewReader(`{"error": "something exploded in EA"}`)
response, cleanup := client.Patch(url.Path, body)
defer cleanup()
Expand Down
2 changes: 1 addition & 1 deletion core/web/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestRBAC_Routemap_Admin(t *testing.T) {

// Assert all admin routes
// no endpoint should return StatusUnauthorized
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)
for _, route := range routesRolesMap {
func() {
var resp *http.Response
Expand Down
16 changes: 8 additions & 8 deletions core/web/bridge_types_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestValidateBridgeNotExist(t *testing.T) {

func BenchmarkBridgeTypesController_Index(b *testing.B) {
app := cltest.NewApplication(b)
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

b.ResetTimer()
for n := 0; n < b.N; n++ {
Expand All @@ -150,7 +150,7 @@ func TestBridgeTypesController_Index(t *testing.T) {

app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

bt, err := setupBridgeControllerIndex(t, app.BridgeORM())
assert.NoError(t, err)
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestBridgeTypesController_Create_Success(t *testing.T) {

app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

resp, cleanup := client.Post(
"/v2/bridge_types",
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestBridgeTypesController_Update_Success(t *testing.T) {

app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

bridgeName := testutils.RandomizeName("BRidgea")
bt := &bridges.BridgeType{
Expand All @@ -272,7 +272,7 @@ func TestBridgeController_Show(t *testing.T) {
app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

bt := &bridges.BridgeType{
Name: bridges.MustParseBridgeName(testutils.RandomizeName("showbridge")),
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestBridgeTypesController_Create_AdapterExistsError(t *testing.T) {
app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

resp, cleanup := client.Post(
"/v2/bridge_types",
Expand All @@ -318,7 +318,7 @@ func TestBridgeTypesController_Create_BindJSONError(t *testing.T) {
app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

resp, cleanup := client.Post(
"/v2/bridge_types",
Expand All @@ -334,7 +334,7 @@ func TestBridgeTypesController_Create_DatabaseError(t *testing.T) {
app := cltest.NewApplication(t)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

resp, cleanup := client.Post(
"/v2/bridge_types",
Expand Down
2 changes: 1 addition & 1 deletion core/web/build_info_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestBuildInfoController_Show_APICredentials(t *testing.T) {
app := cltest.NewApplicationEVMDisabled(t)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

resp, cleanup := client.Get("/v2/build_info")
defer cleanup()
Expand Down
4 changes: 2 additions & 2 deletions core/web/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestCors_DefaultOrigins(t *testing.T) {
t.Run(test.origin, func(t *testing.T) {
app := cltest.NewApplicationWithConfig(t, config)

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

headers := map[string]string{"Origin": test.origin}
resp, cleanup := client.Get("/v2/chains/evm", headers)
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestCors_OverrideOrigins(t *testing.T) {
})
app := cltest.NewApplicationWithConfig(t, config)

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

headers := map[string]string{"Origin": test.origin}
resp, cleanup := client.Get("/v2/chains/evm", headers)
Expand Down
2 changes: 1 addition & 1 deletion core/web/cosmos_chains_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func setupCosmosChainsControllerTestV2(t *testing.T, cfgs ...*cosmos.CosmosConfi
app := cltest.NewApplicationWithConfig(t, cfg)
require.NoError(t, app.Start(testutils.Context(t)))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

return &TestCosmosChainsController{
app: app,
Expand Down
4 changes: 2 additions & 2 deletions core/web/cosmos_keys_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestCosmosKeysController_Create_HappyPath(t *testing.T) {

app := cltest.NewApplicationEVMDisabled(t)
require.NoError(t, app.Start(testutils.Context(t)))
client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)
keyStore := app.GetKeyStore()

response, cleanup := client.Post("/v2/keys/cosmos", nil)
Expand Down Expand Up @@ -98,7 +98,7 @@ func setupCosmosKeysControllerTests(t *testing.T) (cltest.HTTPClientCleaner, key
require.NoError(t, app.Start(testutils.Context(t)))
require.NoError(t, app.KeyStore.Cosmos().Add(cltest.DefaultCosmosKey))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

return client, app.GetKeyStore()
}
2 changes: 1 addition & 1 deletion core/web/dkgencrypt_keys_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func setupDKGEncryptKeysControllerTests(t *testing.T) (cltest.HTTPClientCleaner,
require.NoError(t, app.Start(testutils.Context(t)))
require.NoError(t, app.KeyStore.DKGEncrypt().Add(cltest.DefaultDKGEncryptKey))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

return client, app.GetKeyStore()
}
2 changes: 1 addition & 1 deletion core/web/dkgsign_keys_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func setupDKGSignKeysControllerTests(t *testing.T) (cltest.HTTPClientCleaner, ke
require.NoError(t, app.Start(testutils.Context(t)))
require.NoError(t, app.KeyStore.DKGSign().Add(cltest.DefaultDKGSignKey))

client := app.NewHTTPClient(&cltest.User{})
client := app.NewHTTPClient(nil)

return client, app.GetKeyStore()
}
Loading

0 comments on commit 0af1c02

Please sign in to comment.