Skip to content

Commit 16713a1

Browse files
committed
fix tests
1 parent f1acf8f commit 16713a1

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

internal/provider/project_apikeys_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (d *ProjectAPIKeysDataSource) Read(ctx context.Context, req datasource.Read
8787
return
8888
}
8989

90-
httpResp, err := d.client.V1GetProjectApiKeysWithResponse(ctx, data.ProjectId.ValueString())
90+
httpResp, err := d.client.V1GetProjectApiKeysWithResponse(ctx, data.ProjectId.ValueString(), &api.V1GetProjectApiKeysParams{})
9191
if err != nil {
9292
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read project API keys, got error: %s", err))
9393
return

internal/provider/project_apikeys_data_source_test.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,50 @@
44
package provider
55

66
import (
7-
"fmt"
8-
"regexp"
7+
"net/http"
98
"testing"
109

1110
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/supabase/cli/pkg/api"
12+
"gopkg.in/h2non/gock.v1"
1213
)
1314

1415
func TestAccProjectAPIKeysDataSource(t *testing.T) {
16+
// Setup mock api
17+
defer gock.OffAll()
18+
gock.New("https://api.supabase.com").
19+
Get("/v1/projects/mayuaycdtijbctgqbycg/api-keys").
20+
Times(3).
21+
Reply(http.StatusOK).
22+
JSON([]api.ApiKeyResponse{
23+
{
24+
Name: "anon",
25+
ApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.anon",
26+
},
27+
{
28+
Name: "service_role",
29+
ApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.service_role",
30+
},
31+
})
32+
1533
resource.Test(t, resource.TestCase{
1634
PreCheck: func() { testAccPreCheck(t) },
1735
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
1836
Steps: []resource.TestStep{
1937
// Read testing
2038
{
21-
Config: testAccProjectAPIKeysDataSourceConfig("example-project-id"),
39+
Config: testAccProjectAPIKeysDataSourceConfig,
2240
Check: resource.ComposeAggregateTestCheckFunc(
23-
resource.TestCheckResourceAttr("data.supabase_project_apikeys.test", "project_id", "example-project-id"),
24-
resource.TestCheckResourceAttrSet("data.supabase_project_apikeys.test", "anon_key"),
25-
resource.TestCheckResourceAttrSet("data.supabase_project_apikeys.test", "service_role_key"),
41+
resource.TestCheckResourceAttr("data.supabase_project_apikeys.production", "anon_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.anon"),
42+
resource.TestCheckResourceAttr("data.supabase_project_apikeys.production", "service_role_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.service_role"),
2643
),
2744
},
2845
},
2946
})
3047
}
3148

32-
func testAccProjectAPIKeysDataSourceConfig(projectID string) string {
33-
return fmt.Sprintf(`
34-
data "supabase_project_apikeys" "test" {
35-
project_id = %[1]q
36-
}
37-
`, projectID)
38-
}
39-
40-
func TestAccProjectAPIKeysDataSource_NotFound(t *testing.T) {
41-
resource.Test(t, resource.TestCase{
42-
PreCheck: func() { testAccPreCheck(t) },
43-
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
44-
Steps: []resource.TestStep{
45-
{
46-
Config: testAccProjectAPIKeysDataSourceConfig("non-existent-project"),
47-
ExpectError: regexp.MustCompile("Unable to read project API keys"),
48-
},
49-
},
50-
})
49+
const testAccProjectAPIKeysDataSourceConfig = `
50+
data "supabase_project_apikeys" "production" {
51+
project_id = "mayuaycdtijbctgqbycg"
5152
}
53+
`

0 commit comments

Comments
 (0)