Skip to content

Commit 756005e

Browse files
mock all API request using gock to fix
1 parent dad4a5c commit 756005e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

internal/services/services_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,43 @@ func TestRun(t *testing.T) {
3636
require.NoError(t, utils.InitConfig(utils.InitParams{
3737
ProjectId: projectRef,
3838
}, fsys))
39-
40-
// Set project reference in flags
4139
flags.ProjectRef = projectRef
4240

41+
// Mock all API requests
42+
defer gock.OffAll()
43+
44+
// Mock API keys
45+
gock.New(utils.DefaultApiHost).
46+
Get("/v1/projects/" + projectRef + "/api-keys").
47+
Reply(200).
48+
JSON([]map[string]string{{"name": "anon", "api_key": "test-key"}})
49+
50+
// Mock database version
51+
gock.New(utils.DefaultApiHost).
52+
Get("/v1/projects").
53+
Reply(200).
54+
JSON([]map[string]interface{}{
55+
{
56+
"id": projectRef,
57+
"database": map[string]string{"version": "1.0.0"},
58+
},
59+
})
60+
61+
// Mock auth version
62+
gock.New("https://" + utils.GetSupabaseHost(projectRef)).
63+
Get("/auth/v1/health").
64+
Reply(200).
65+
JSON(map[string]string{"version": "2.0.0"})
66+
67+
// Mock postgrest version
68+
gock.New("https://" + utils.GetSupabaseHost(projectRef)).
69+
Get("/rest/v1/").
70+
Reply(200).
71+
JSON(map[string]interface{}{
72+
"swagger": "2.0",
73+
"info": map[string]string{"version": "3.0.0"},
74+
})
75+
4376
// Execute: Call the Run function
4477
err := Run(context.Background(), fsys)
4578

0 commit comments

Comments
 (0)