fix: configure conformance tests

This commit is contained in:
2026-01-31 17:13:02 +01:00
parent 7cbcc3f04c
commit 4784f4c4d5
8 changed files with 47 additions and 94 deletions

View File

@@ -11,12 +11,10 @@ import "@proxmox/proxmox.pkl"
forma { forma {
new formae.Stack { new formae.Stack {
label = "default"
description = "Default stack for example resources" description = "Default stack for example resources"
} }
new formae.Target { new formae.Target {
label = "my-target"
namespace = "PROXMOX" namespace = "PROXMOX"
// Add your provider-specific configuration here // Add your provider-specific configuration here
// For typed config, create a Config class in your schema: // For typed config, create a Config class in your schema:
@@ -27,7 +25,6 @@ forma {
} }
new example.ExampleResource { new example.ExampleResource {
label = "my-resource"
name = "My Example Resource" name = "My Example Resource"
description = "This is an example resource" description = "This is an example resource"
region = "us-east-1" region = "us-east-1"

View File

@@ -67,7 +67,7 @@ func (p *Plugin) LabelConfig() plugin.LabelConfig {
return plugin.LabelConfig{ return plugin.LabelConfig{
// Default JSONPath query to extract label from resources // Default JSONPath query to extract label from resources
// Example for tagged resources: $.Tags[?(@.Key=='Name')].Value // Example for tagged resources: $.Tags[?(@.Key=='Name')].Value
DefaultQuery: "$.name", DefaultQuery: "$.hostname",
// Override for specific resource types // Override for specific resource types
ResourceOverrides: map[string]string{ ResourceOverrides: map[string]string{
@@ -256,7 +256,6 @@ func (p *Plugin) Update(ctx context.Context, req *resource.UpdateRequest) (*reso
if prior == nil { if prior == nil {
p.Create(ctx, &resource.CreateRequest{ p.Create(ctx, &resource.CreateRequest{
ResourceType: req.ResourceType, ResourceType: req.ResourceType,
Label: req.Label,
Properties: req.DesiredProperties, Properties: req.DesiredProperties,
TargetConfig: req.TargetConfig, TargetConfig: req.TargetConfig,
}) })

View File

@@ -4,8 +4,10 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"io" "io"
"log"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"testing" "testing"
"time" "time"
@@ -39,7 +41,6 @@ func TestCreate(t *testing.T) {
req := &resource.CreateRequest{ req := &resource.CreateRequest{
ResourceType: "PROXMOX::Service::LXC", ResourceType: "PROXMOX::Service::LXC",
Label: "test-create",
Properties: propertiesJSON, Properties: propertiesJSON,
TargetConfig: testTargetConfig(), TargetConfig: testTargetConfig(),
} }
@@ -163,6 +164,8 @@ func TestList(t *testing.T) {
}) })
require.NoError(t, err, "ListRequest should not return an error") require.NoError(t, err, "ListRequest should not return an error")
log.Printf("Received Ids: %s", strings.Join(result.NativeIDs, ", "))
require.Contains(t, result.NativeIDs, "200", "List should include created LXC") require.Contains(t, result.NativeIDs, "200", "List should include created LXC")
} }

View File

@@ -6,7 +6,7 @@ import "@formae/formae.pkl"
type = "PROXMOX::Service::LXC" type = "PROXMOX::Service::LXC"
identifier = "$.vmid" identifier = "$.vmid"
} }
class ExampleResource extends formae.Resource { class LXC extends formae.Resource {
fixed hidden type: String = "PROXMOX::Service::LXC" fixed hidden type: String = "PROXMOX::Service::LXC"
@formae.FieldHint { createOnly = true } @formae.FieldHint { createOnly = true }
@@ -16,7 +16,7 @@ class ExampleResource extends formae.Resource {
ostemplate: String ostemplate: String
@formae.FieldHint {} @formae.FieldHint {}
name: String hostname: String
@formae.FieldHint {} @formae.FieldHint {}
description: String = "No description" description: String = "No description"

2
testdata/PklProject vendored
View File

@@ -7,6 +7,6 @@ dependencies {
// Formae schema - fetched from public registry // Formae schema - fetched from public registry
["formae"] { ["formae"] {
uri = "package://hub.platform.engineering/plugins/pkl/schema/pkl/formae/formae@0.80.0" uri = "package://hub.platform.engineering/plugins/pkl/schema/pkl/formae/formae@0.80.1"
} }
} }

View File

@@ -1,50 +1,35 @@
/* /*
* Conformance Test: Replace Resource * Conformance Test: Create Resource
* *
* This file modifies a createOnly field to trigger resource replacement. * This file defines the initial resource state for conformance testing.
* Changes from resource.pkl: * The conformance test harness will apply this file first.
* - region: changed from "us-east-1" to "us-west-2"
*
* The region field has createOnly=true, so formae should delete the
* existing resource and create a new one with the new region.
*/ */
amends "@formae/forma.pkl" amends "@formae/forma.pkl"
import "@formae/formae.pkl" import "@formae/formae.pkl"
import "@proxmox/proxmox.pkl" import "@proxmox/proxmox.pkl"
local stackName = "plugin-sdk-test-stack"
local testRunID = read("env:FORMAE_TEST_RUN_ID") local testRunID = read("env:FORMAE_TEST_RUN_ID")
local stackName = "conformance-test-\(testRunID)"
forma { forma {
new formae.Stack { new formae.Stack {
label = stackName label = stackName
description = "Plugin SDK conformance test stack"
} }
new formae.Target { new formae.Target {
label = "example-target" label = "target"
namespace = "PROXMOX" config = new proxmox.Config {
config = new Mapping { url: "https://proxmox.mid:8006"
["region"] = "us-west-2" // CHANGED to match resource node: proxmox
} }
} }
new example.ExampleResource { new proxmox.LXC {
label = "plugin-sdk-test-resource" label = "test-lxc"
name = "formae-plugin-sdk-test-\(testRunID)" vmid = "220"
description = "Test resource for plugin SDK conformance tests" hostname = "test-lxc"
region = "us-west-2" // CHANGED - triggers replacement description = "some other description"
ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz"
endpoint = new example.Endpoint {
url = "https://api.example.com"
port = 8080
protocol = "https"
}
tags = new Listing {
new example.Tag { key = "Environment"; value = "test" }
new example.Tag { key = "ManagedBy"; value = "formae" }
}
} }
} }

View File

@@ -1,54 +1,35 @@
/* /*
* Conformance Test: Update Resource (in-place) * Conformance Test: Create Resource
* *
* This file modifies mutable fields to trigger an in-place update. * This file defines the initial resource state for conformance testing.
* Changes from resource.pkl: * The conformance test harness will apply this file first.
* - name: added "-updated" suffix
* - description: changed text
* - endpoint.port: changed from 8080 to 9090
* - tags: added a new tag
*
* These fields do NOT have createOnly=true, so formae should update
* the resource in place without replacement.
*/ */
amends "@formae/forma.pkl" amends "@formae/forma.pkl"
import "@formae/formae.pkl" import "@formae/formae.pkl"
import "@proxmox/proxmox.pkl" import "@proxmox/proxmox.pkl"
local stackName = "plugin-sdk-test-stack"
local testRunID = read("env:FORMAE_TEST_RUN_ID") local testRunID = read("env:FORMAE_TEST_RUN_ID")
local stackName = "conformance-test-\(testRunID)"
forma { forma {
new formae.Stack { new formae.Stack {
label = stackName label = stackName
description = "Plugin SDK conformance test stack"
} }
new formae.Target { new formae.Target {
label = "example-target" label = "target"
namespace = "PROXMOX" config = new proxmox.Config {
config = new Mapping { url: "https://proxmox.mid:8006"
["region"] = "us-east-1" node: proxmox
} }
} }
new example.ExampleResource { new proxmox.LXC {
label = "plugin-sdk-test-resource" label = "test-lxc"
name = "formae-plugin-sdk-test-\(testRunID)-updated" // CHANGED vmid = "210"
description = "Test resource - UPDATED" // CHANGED hostname = "test-lxc"
region = "us-east-1" // unchanged (createOnly) description = "some other description"
ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz"
endpoint = new example.Endpoint {
url = "https://api.example.com"
port = 9090 // CHANGED from 8080
protocol = "https"
}
tags = new Listing {
new example.Tag { key = "Environment"; value = "test" }
new example.Tag { key = "ManagedBy"; value = "formae" }
new example.Tag { key = "UpdatedAt"; value = "conformance-test" } // ADDED
}
} }
} }

34
testdata/resource.pkl vendored
View File

@@ -9,41 +9,29 @@ import "@formae/formae.pkl"
import "@proxmox/proxmox.pkl" import "@proxmox/proxmox.pkl"
local stackName = "plugin-sdk-test-stack"
// Read the test run ID from environment variable set by the test harness
// This ensures consistent naming within a test run but unique names between runs
local testRunID = read("env:FORMAE_TEST_RUN_ID") local testRunID = read("env:FORMAE_TEST_RUN_ID")
local stackName = "conformance-test-\(testRunID)"
forma { forma {
new formae.Stack { new formae.Stack {
label = stackName label = stackName
description = "Plugin SDK conformance test stack" description = ""
} }
new formae.Target { new formae.Target {
label = "example-target" label = "target"
namespace = "PROXMOX" namespace = "PROXMOX"
// TODO: Add your provider-specific configuration
config = new Mapping { config = new Mapping {
["region"] = "us-east-1" ["url"] = "https://proxmox.mid:8006"
["node"] = "proxmox"
} }
} }
new example.ExampleResource { new proxmox.LXC {
label = "plugin-sdk-test-resource" label = "test-lxc"
name = "formae-plugin-sdk-test-\(testRunID)" vmid = "210"
description = "Test resource for plugin SDK conformance tests" hostname = "test-lxc"
region = "us-east-1" description = "no description provided"
ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz"
endpoint = new example.Endpoint {
url = "https://api.example.com"
port = 8080
protocol = "https"
}
tags = new Listing {
new example.Tag { key = "Environment"; value = "test" }
new example.Tag { key = "ManagedBy"; value = "formae" }
}
} }
} }