@@ -13,56 +13,55 @@ import (
1313)
1414
1515func TestGetDatabaseVersion (t * testing.T ) {
16- t .Run ("retrieves database version successfully" , func (t * testing.T ) {
17- token := apitest .RandomAccessToken (t )
18- t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
16+ // Setup valid access token
17+ token := apitest .RandomAccessToken (t )
18+ t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
19+ // Setup valid project ref
20+ projectRef := apitest .RandomProjectRef ()
1921
22+ t .Run ("retrieves database version successfully" , func (t * testing.T ) {
23+ // Setup mock api
2024 defer gock .OffAll ()
21- projectRef := apitest .RandomProjectRef ()
22- mockPostgres := api.V1ProjectWithDatabaseResponse {Id : projectRef }
25+ mockPostgres := api.V1ProjectWithDatabaseResponse {}
2326 mockPostgres .Database .Version = "14.1.0.99"
2427 gock .New (utils .DefaultApiHost ).
2528 Get ("/v1/projects/" + projectRef ).
2629 Reply (http .StatusOK ).
2730 JSON (mockPostgres )
28-
31+ // Run test
2932 version , err := GetDatabaseVersion (context .Background (), projectRef )
30-
33+ // Check error
3134 assert .NoError (t , err )
3235 assert .Equal (t , "14.1.0.99" , version )
3336 assert .Empty (t , apitest .ListUnmatchedRequests ())
3437 })
3538
3639 t .Run ("handles project not found" , func (t * testing.T ) {
37- token := apitest .RandomAccessToken (t )
38- t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
39-
40+ // Setup mock api
4041 defer gock .OffAll ()
4142 projectRef := apitest .RandomProjectRef ()
4243 gock .New (utils .DefaultApiHost ).
4344 Get ("/v1/projects/" + projectRef ).
4445 Reply (http .StatusNotFound )
45-
46+ // Run test
4647 version , err := GetDatabaseVersion (context .Background (), projectRef )
47-
48+ // Check error
4849 assert .ErrorContains (t , err , "unexpected retrieve project status 404:" )
4950 assert .Empty (t , version )
5051 assert .Empty (t , apitest .ListUnmatchedRequests ())
5152 })
5253
5354 t .Run ("handles empty database version" , func (t * testing.T ) {
54- token := apitest .RandomAccessToken (t )
55- t .Setenv ("SUPABASE_ACCESS_TOKEN" , string (token ))
56-
55+ // Setup mock api
5756 defer gock .OffAll ()
5857 projectRef := apitest .RandomProjectRef ()
5958 gock .New (utils .DefaultApiHost ).
6059 Get ("/v1/projects/" + projectRef ).
6160 Reply (http .StatusOK ).
62- JSON (api.V1ProjectWithDatabaseResponse {Id : projectRef })
63-
61+ JSON (api.V1ProjectWithDatabaseResponse {})
62+ // Run test
6463 version , err := GetDatabaseVersion (context .Background (), projectRef )
65-
64+ // Check error
6665 assert .ErrorIs (t , err , errDatabaseVersion )
6766 assert .Empty (t , version )
6867 assert .Empty (t , apitest .ListUnmatchedRequests ())
0 commit comments