Skip to content

Commit 750b91d

Browse files
committed
Test proxy data source against Kernel
1 parent 8de340c commit 750b91d

3 files changed

Lines changed: 138 additions & 2 deletions

File tree

.github/workflows/acceptance.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Profile data source
4040
package: ./internal/datasources/profile
4141
project_id_required: true
42+
- name: Proxy data source
43+
package: ./internal/datasources/proxy
44+
project_id_required: true
4245
# Keep the job timeout above the go test timeout so Go can report the test
4346
# timeout before the runner stops the job. Either hard timeout can bypass
4447
# 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
@@ -45,7 +45,7 @@ operation. Secrets must remain GitHub Actions secrets and must not be printed.
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. |
4747
| `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. |
48-
| `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. |
48+
| `kernel_proxy` data source | Test present | A uniquely created managed datacenter proxy is read by canonical ID and exact name through explicit and provider-default project scope; durable type/protocol metadata, no-drift planning, and post-cleanup coded `not_found` are verified without fixture credentials. | None. |
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. |
5151
| Profile, proxy, deployment, and API-key resources | Deferred; unregistered | No provider surfaces yet. | Enter the matrix only after their documented API/SDK/state blockers are resolved and implementation lands. |
@@ -55,7 +55,7 @@ against the release commit. The release record below supplies that evidence.
5555

5656
## Current Commands
5757

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

6060
```sh
6161
go test -count=1 -timeout=30m -v ./internal/resources/project -run TestAcc
@@ -64,6 +64,7 @@ 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
6666
go test -count=1 -timeout=30m -v ./internal/datasources/profile -run TestAcc
67+
go test -count=1 -timeout=30m -v ./internal/datasources/proxy -run TestAcc
6768
go test -count=1 -timeout=30m -v ./internal/datasources/browserpool -run TestAcc
6869
```
6970

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package proxy_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/kernelclient"
14+
"github.com/kernel/terraform-provider-kernel/internal/projectscope"
15+
)
16+
17+
func TestAccProxyDataSourceByIDAndName(t *testing.T) {
18+
if os.Getenv("TF_ACC") != "1" {
19+
t.Skip("set TF_ACC=1 to run Terraform acceptance tests")
20+
}
21+
acctest.PreCheck(t)
22+
23+
projectID := os.Getenv(acctest.EnvProjectID)
24+
if projectID == "" {
25+
t.Fatalf("%s must be set for the proxy data source acceptance test", acctest.EnvProjectID)
26+
}
27+
28+
name := acctest.UniqueName(t, "proxy-data")
29+
id := testAccCreateProxyFixture(t, projectID, name)
30+
config := testAccProxyDataSourceConfig(id, name, projectID)
31+
32+
resource.Test(t, resource.TestCase{
33+
PreCheck: func() { acctest.PreCheck(t) },
34+
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories(),
35+
Steps: []resource.TestStep{
36+
{
37+
Config: config,
38+
Check: resource.ComposeAggregateTestCheckFunc(
39+
resource.TestCheckResourceAttr("data.kernel_proxy.by_id", "id", id),
40+
resource.TestCheckResourceAttr("data.kernel_proxy.by_id", "name", name),
41+
resource.TestCheckResourceAttr("data.kernel_proxy.by_id", "project_id", projectID),
42+
resource.TestCheckResourceAttr("data.kernel_proxy.by_id", "type", "datacenter"),
43+
resource.TestCheckResourceAttr("data.kernel_proxy.by_id", "protocol", "https"),
44+
resource.TestCheckResourceAttr("data.kernel_proxy.by_name", "id", id),
45+
resource.TestCheckResourceAttr("data.kernel_proxy.by_name", "name", name),
46+
resource.TestCheckNoResourceAttr("data.kernel_proxy.by_name", "project_id"),
47+
resource.TestCheckResourceAttr("data.kernel_proxy.by_name", "type", "datacenter"),
48+
resource.TestCheckResourceAttr("data.kernel_proxy.by_name", "protocol", "https"),
49+
),
50+
},
51+
{
52+
Config: config,
53+
PlanOnly: true,
54+
},
55+
},
56+
})
57+
}
58+
59+
func testAccCreateProxyFixture(t *testing.T, projectID, name string) string {
60+
t.Helper()
61+
62+
ctx, cancel := context.WithTimeout(context.Background(), kernelclient.DefaultRequestTimeout)
63+
defer cancel()
64+
65+
proxy, err := acctest.ClientFromEnv().CreateProxy(ctx, projectID, kernel.ProxyNewParams{
66+
Name: kernel.String(name),
67+
Type: kernel.ProxyNewParamsTypeDatacenter,
68+
})
69+
if err != nil {
70+
t.Fatalf("create Kernel proxy fixture: %v", err)
71+
}
72+
if proxy == nil || proxy.ID == "" {
73+
t.Fatal("Kernel returned an empty proxy fixture response")
74+
}
75+
76+
// Cleanups run last-in-first-out, so deletion must register after verification.
77+
testAccRequireProxyDeleted(t, projectID, proxy.ID)
78+
testAccDeleteProxy(t, projectID, proxy.ID)
79+
80+
if proxy.Name != name {
81+
t.Fatalf("created Kernel proxy name = %q, want %q", proxy.Name, name)
82+
}
83+
if proxy.Type != kernel.ProxyNewResponseTypeDatacenter {
84+
t.Fatalf("created Kernel proxy type = %q, want datacenter", proxy.Type)
85+
}
86+
return proxy.ID
87+
}
88+
89+
func testAccDeleteProxy(t *testing.T, projectID, id string) {
90+
t.Helper()
91+
92+
t.Cleanup(func() {
93+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
94+
defer cancel()
95+
96+
if err := acctest.ClientFromEnv().DeleteProxy(ctx, projectID, id); err != nil && !acctest.IsNotFound(err) {
97+
t.Errorf("cleanup Kernel proxy %s: %v", id, err)
98+
}
99+
})
100+
}
101+
102+
func testAccRequireProxyDeleted(t *testing.T, projectID, id string) {
103+
t.Helper()
104+
105+
t.Cleanup(func() {
106+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
107+
defer cancel()
108+
109+
_, err := acctest.ClientFromEnv().GetProxy(ctx, projectID, id)
110+
if projectscope.IsNotFound(err) {
111+
return
112+
}
113+
if err != nil {
114+
t.Errorf("read Kernel proxy %s after cleanup: %v", id, err)
115+
return
116+
}
117+
t.Errorf("Kernel proxy %s still exists after cleanup", id)
118+
})
119+
}
120+
121+
func testAccProxyDataSourceConfig(id, name, projectID string) string {
122+
return acctest.ProviderConfig() + fmt.Sprintf(`
123+
data "kernel_proxy" "by_id" {
124+
id = %q
125+
project_id = %q
126+
}
127+
128+
data "kernel_proxy" "by_name" {
129+
name = %q
130+
}
131+
`, id, projectID, name)
132+
}

0 commit comments

Comments
 (0)