|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package provider |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "regexp" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAccProjectAPIKeysDataSource(t *testing.T) { |
| 15 | + resource.Test(t, resource.TestCase{ |
| 16 | + PreCheck: func() { testAccPreCheck(t) }, |
| 17 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 18 | + Steps: []resource.TestStep{ |
| 19 | + // Read testing |
| 20 | + { |
| 21 | + Config: testAccProjectAPIKeysDataSourceConfig("example-project-id"), |
| 22 | + 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"), |
| 26 | + ), |
| 27 | + }, |
| 28 | + }, |
| 29 | + }) |
| 30 | +} |
| 31 | + |
| 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 | + }) |
| 51 | +} |
0 commit comments