Skip to content

Commit acf09bb

Browse files
committed
Test profile data source against Kernel
1 parent d46c205 commit acf09bb

3 files changed

Lines changed: 116 additions & 2 deletions

File tree

.github/workflows/acceptance.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
- name: Extension data source
3737
package: ./internal/datasources/extension
3838
project_id_required: true
39+
- name: Profile data source
40+
package: ./internal/datasources/profile
41+
project_id_required: true
3942
# Keep the job timeout above the go test timeout so Go can report the test
4043
# timeout before the runner stops the job. Either hard timeout can bypass
4144
# t.Cleanup, so release operators still inspect for leaked test resources.

docs/acceptance.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ operation. Secrets must remain GitHub Actions secrets and must not be printed.
4444
| `kernel_browser_pool` data source | Test present | A uniquely created pool is read by canonical ID and byte-exact name, including normalized durable configuration, a no-drift plan, and post-destroy coded `not_found` verification. | None. |
4545
| `kernel_project` data source | Test present | A uniquely created project is read by canonical ID and exact name; the provider default resolves the configured project; metadata, no-drift planning, and post-destroy coded `not_found` are verified. | None. |
4646
| `kernel_extension` data source | Test present | A uniquely uploaded extension is read by canonical ID and exact name through explicit and provider-default project scope; metadata, no-drift planning, and post-destroy coded `not_found` are verified. | None. |
47-
| `kernel_profile` data source | Test missing; tag blocker | Unit and fake-client tests only. | Add durable SDK fixture create/delete helpers, then verify ID/name lookup and cleanup. Do not model runtime-written profile contents. |
47+
| `kernel_profile` data source | Test present | A uniquely created durable profile is read by canonical ID and exact name through explicit and provider-default project scope; metadata, no-drift planning, and post-cleanup coded `not_found` are verified. | None. |
4848
| `kernel_proxy` data source | Test missing; tag blocker | Unit and fake-client tests only. | Add a durable, non-secret-leaking proxy fixture strategy and verify ID/name lookup, masked metadata, and cleanup. |
4949
| `kernel_app` data source | Fixture blocked; tag blocker | Unit, SDK transport, pagination, ambiguity, project-scope, and Framework state tests only. | Provide a release-owned running deployment fixture or a deterministic durable deployment setup. Verify exact app/version lookup without invocation and without exposing env values. |
5050
| `kernel_api_key` data source | Deferred; unregistered | No provider surface yet. | Wait for a tagged SDK with exact-name filtering, then add masked ID/name lookup acceptance. |
@@ -55,14 +55,15 @@ against the release commit. The release record below supplies that evidence.
5555

5656
## Current Commands
5757

58-
Run the six existing packages independently for fast failure isolation:
58+
Run the seven existing packages independently for fast failure isolation:
5959

6060
```sh
6161
go test -count=1 -timeout=30m -v ./internal/resources/project -run TestAcc
6262
go test -count=1 -timeout=30m -v ./internal/datasources/project -run TestAcc
6363
go test -count=1 -timeout=30m -v ./internal/resources/browserpool -run TestAcc
6464
go test -count=1 -timeout=30m -v ./internal/resources/extension -run TestAcc
6565
go test -count=1 -timeout=30m -v ./internal/datasources/extension -run TestAcc
66+
go test -count=1 -timeout=30m -v ./internal/datasources/profile -run TestAcc
6667
go test -count=1 -timeout=30m -v ./internal/datasources/browserpool -run TestAcc
6768
```
6869

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package profile_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"testing"
8+
"time"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
kernel "github.com/kernel/kernel-go-sdk"
12+
"github.com/kernel/terraform-provider-kernel/internal/acctest"
13+
"github.com/kernel/terraform-provider-kernel/internal/projectscope"
14+
)
15+
16+
func TestAccProfileDataSourceByIDAndName(t *testing.T) {
17+
if os.Getenv("TF_ACC") != "1" {
18+
t.Skip("set TF_ACC=1 to run Terraform acceptance tests")
19+
}
20+
acctest.PreCheck(t)
21+
22+
projectID := os.Getenv(acctest.EnvProjectID)
23+
if projectID == "" {
24+
t.Fatalf("%s must be set for the profile data source acceptance test", acctest.EnvProjectID)
25+
}
26+
27+
name := acctest.UniqueName(t, "profile-data")
28+
id := testAccCreateProfileFixture(t, projectID, name)
29+
config := testAccProfileDataSourceConfig(id, name, projectID)
30+
31+
resource.Test(t, resource.TestCase{
32+
PreCheck: func() { acctest.PreCheck(t) },
33+
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories(),
34+
Steps: []resource.TestStep{
35+
{
36+
Config: config,
37+
Check: resource.ComposeAggregateTestCheckFunc(
38+
resource.TestCheckResourceAttr("data.kernel_profile.by_id", "id", id),
39+
resource.TestCheckResourceAttr("data.kernel_profile.by_id", "name", name),
40+
resource.TestCheckResourceAttr("data.kernel_profile.by_id", "project_id", projectID),
41+
resource.TestCheckResourceAttrSet("data.kernel_profile.by_id", "created_at"),
42+
resource.TestCheckResourceAttr("data.kernel_profile.by_name", "id", id),
43+
resource.TestCheckResourceAttr("data.kernel_profile.by_name", "name", name),
44+
resource.TestCheckNoResourceAttr("data.kernel_profile.by_name", "project_id"),
45+
resource.TestCheckResourceAttrSet("data.kernel_profile.by_name", "created_at"),
46+
),
47+
},
48+
{
49+
Config: config,
50+
PlanOnly: true,
51+
},
52+
},
53+
})
54+
}
55+
56+
func testAccCreateProfileFixture(t *testing.T, projectID, name string) string {
57+
t.Helper()
58+
59+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
60+
defer cancel()
61+
62+
profile, err := acctest.ClientFromEnv().CreateProfile(ctx, projectID, kernel.ProfileNewParams{Name: kernel.String(name)})
63+
if err != nil {
64+
t.Fatalf("create Kernel profile fixture: %v", err)
65+
}
66+
if profile == nil || profile.ID == "" {
67+
t.Fatal("Kernel returned an empty profile fixture response")
68+
}
69+
70+
// Cleanups run last-in-first-out, so deletion must register after verification.
71+
testAccRequireProfileDeleted(t, projectID, profile.ID)
72+
acctest.CleanupProfile(t, projectID, profile.ID)
73+
74+
if profile.Name != name {
75+
t.Fatalf("created Kernel profile name = %q, want %q", profile.Name, name)
76+
}
77+
return profile.ID
78+
}
79+
80+
func testAccRequireProfileDeleted(t *testing.T, projectID, id string) {
81+
t.Helper()
82+
83+
t.Cleanup(func() {
84+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
85+
defer cancel()
86+
87+
_, err := acctest.ClientFromEnv().GetProfile(ctx, projectID, id)
88+
if projectscope.IsNotFound(err) {
89+
return
90+
}
91+
if err != nil {
92+
t.Errorf("read Kernel profile %s after cleanup: %v", id, err)
93+
return
94+
}
95+
t.Errorf("Kernel profile %s still exists after cleanup", id)
96+
})
97+
}
98+
99+
func testAccProfileDataSourceConfig(id, name, projectID string) string {
100+
return acctest.ProviderConfig() + fmt.Sprintf(`
101+
data "kernel_profile" "by_id" {
102+
id = %q
103+
project_id = %q
104+
}
105+
106+
data "kernel_profile" "by_name" {
107+
name = %q
108+
}
109+
`, id, projectID, name)
110+
}

0 commit comments

Comments
 (0)