Skip to content

Commit 6530018

Browse files
authored
Merge pull request #152 from lxfontes/lxfontes/manifest-json
fix: wasmbus trait decoding
2 parents 26123a1 + 1ad22d4 commit 6530018

File tree

4 files changed

+103
-9
lines changed

4 files changed

+103
-9
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"kind": "Application",
3+
"apiVersion": "core.oam.dev/v1beta1",
4+
"metadata": {
5+
"name": "rust-hello-world",
6+
"namespace": "default",
7+
"uid": "8463bb90-0c03-4a1c-b21f-e8446b84184f",
8+
"resourceVersion": "551",
9+
"generation": 1,
10+
"creationTimestamp": "2025-01-07T19:21:56Z",
11+
"annotations": {
12+
"description": "HTTP hello world demo in Rust, using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)",
13+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"core.oam.dev/v1beta1\",\"kind\":\"Application\",\"metadata\":{\"annotations\":{\"description\":\"HTTP hello world demo in Rust, using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)\",\"wasmcloud.dev/authors\":\"wasmCloud team\",\"wasmcloud.dev/categories\":\"http,http-server,rust,hello-world,example\\n\",\"wasmcloud.dev/homepage\":\"https://github.com/wasmCloud/wasmCloud/tree/main/examples/rust/components/http-hello-world\",\"wasmcloud.dev/readme-md-url\":\"https://github.com/wasmCloud/wasmCloud/blob/main/examples/rust/components/http-hello-world/README.md\",\"wasmcloud.dev/source-url\":\"https://github.com/wasmCloud/wasmCloud/blob/main/examples/rust/components/http-hello-world/wadm.yaml\"},\"name\":\"rust-hello-world\",\"namespace\":\"default\"},\"spec\":{\"components\":[{\"name\":\"http-component\",\"properties\":{\"image\":\"ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0\"},\"traits\":[{\"properties\":{\"instances\":1},\"type\":\"spreadscaler\"}],\"type\":\"component\"},{\"name\":\"httpserver\",\"properties\":{\"image\":\"ghcr.io/wasmcloud/http-server:0.23.1\"},\"traits\":[{\"properties\":{\"instances\":1},\"type\":\"spreadscaler\"},{\"properties\":{\"interfaces\":[\"incoming-handler\"],\"namespace\":\"wasi\",\"package\":\"http\",\"source_config\":[{\"name\":\"default-http\",\"properties\":{\"address\":\"0.0.0.0:8080\"}}],\"target\":\"http-component\"},\"type\":\"link\"}],\"type\":\"capability\"}]}}\n",
14+
"wasmcloud.dev/authors": "wasmCloud team",
15+
"wasmcloud.dev/categories": "http,http-server,rust,hello-world,example\n",
16+
"wasmcloud.dev/homepage": "https://github.com/wasmCloud/wasmCloud/tree/main/examples/rust/components/http-hello-world",
17+
"wasmcloud.dev/readme-md-url": "https://github.com/wasmCloud/wasmCloud/blob/main/examples/rust/components/http-hello-world/README.md",
18+
"wasmcloud.dev/source-url": "https://github.com/wasmCloud/wasmCloud/blob/main/examples/rust/components/http-hello-world/wadm.yaml"
19+
},
20+
"managedFields": [
21+
{
22+
"manager": "kubectl-client-side-apply",
23+
"operation": "Update",
24+
"apiVersion": "core.oam.dev/v1beta1",
25+
"time": "2025-01-07T19:21:56Z",
26+
"fieldsType": "FieldsV1",
27+
"fieldsV1": {
28+
"f:metadata": {
29+
"f:annotations": {
30+
".": {},
31+
"f:description": {},
32+
"f:kubectl.kubernetes.io/last-applied-configuration": {},
33+
"f:wasmcloud.dev/authors": {},
34+
"f:wasmcloud.dev/categories": {},
35+
"f:wasmcloud.dev/homepage": {},
36+
"f:wasmcloud.dev/readme-md-url": {},
37+
"f:wasmcloud.dev/source-url": {}
38+
}
39+
},
40+
"f:spec": { ".": {}, "f:components": {} }
41+
}
42+
}
43+
]
44+
},
45+
"spec": {
46+
"components": [
47+
{
48+
"name": "http-component",
49+
"type": "component",
50+
"properties": {
51+
"image": "ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0"
52+
},
53+
"traits": [{ "type": "spreadscaler", "properties": { "instances": 1 } }]
54+
},
55+
{
56+
"name": "httpserver",
57+
"type": "capability",
58+
"properties": { "image": "ghcr.io/wasmcloud/http-server:0.23.1" },
59+
"traits": [
60+
{ "type": "spreadscaler", "properties": { "instances": 1 } },
61+
{
62+
"type": "link",
63+
"properties": {
64+
"interfaces": ["incoming-handler"],
65+
"namespace": "wasi",
66+
"package": "http",
67+
"source_config": [
68+
{
69+
"name": "default-http",
70+
"properties": { "address": "0.0.0.0:8080" }
71+
}
72+
],
73+
"target": "http-component"
74+
}
75+
}
76+
]
77+
}
78+
]
79+
},
80+
"status": {}
81+
}

x/wasmbus/wadm/types.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,29 @@ type TargetConfigDefinition struct {
198198

199199
type rawTargetConfigDefinition TargetConfigDefinition
200200

201-
func (t *TargetConfigDefinition) UnmarshalYAML(data []byte) error {
201+
func (t *TargetConfigDefinition) unmarshal(data []byte, fn func([]byte, interface{}) error) error {
202202
*t = TargetConfigDefinition{}
203-
if err := yaml.Unmarshal(data, &t.Name); err == nil {
203+
if err := fn(data, &t.Name); err == nil {
204204
return nil
205205
}
206206

207207
rt := &rawTargetConfigDefinition{}
208-
if err := yaml.Unmarshal(data, rt); err != nil {
208+
if err := fn(data, rt); err != nil {
209209
return err
210210
}
211211
*t = TargetConfigDefinition(*rt)
212212

213213
return nil
214214
}
215215

216+
func (t *TargetConfigDefinition) UnmarshalJSON(data []byte) error {
217+
return t.unmarshal(data, json.Unmarshal)
218+
}
219+
220+
func (t *TargetConfigDefinition) UnmarshalYAML(data []byte) error {
221+
return t.unmarshal(data, yaml.Unmarshal)
222+
}
223+
216224
type LinkProperty struct {
217225
Name string `json:"name,omitempty" yaml:"name,omitempty"`
218226

x/wasmbus/wasmbustest/helpers.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"flag"
88
"os"
99
"os/exec"
10-
"testing"
1110
"time"
1211

1312
"github.com/nats-io/nats.go"
@@ -21,6 +20,13 @@ const (
2120
ValidProvider = "ghcr.io/wasmcloud/http-client:0.12.0"
2221
)
2322

23+
// interface that can be fulfilled by any testing.T implementation ( std, ginkgo, testify )
24+
type TestingT interface {
25+
Helper()
26+
Fatalf(string, ...any)
27+
Logf(string, ...any)
28+
}
29+
2430
func CheckWadm() error {
2531
return Exec("wash", "app", "list")
2632
}
@@ -35,14 +41,14 @@ func Exec(bin string, args ...string) error {
3541
return cmd.Run()
3642
}
3743

38-
func WashDeploy(t *testing.T, path string) {
44+
func WashDeploy(t TestingT, path string) {
3945
t.Helper()
4046
if err := Exec("wash", "app", "deploy", path); err != nil {
4147
t.Fatalf("failed to deploy manifest: %v", err)
4248
}
4349
}
4450

45-
func WithWash(t *testing.T) (*nats.Conn, func(*testing.T)) {
51+
func WithWash(t TestingT) (*nats.Conn, func(TestingT)) {
4652
t.Helper()
4753

4854
if err := Exec("wash", "up", "-d"); err != nil {
@@ -73,7 +79,7 @@ func WithWash(t *testing.T) (*nats.Conn, func(*testing.T)) {
7379
return nil, nil
7480
}
7581

76-
return nc, func(*testing.T) {
82+
return nc, func(TestingT) {
7783
nc.Close()
7884
if *showOutput {
7985
_ = Exec("wash", "get", "inventory")

x/wasmbus/wasmbustest/nats.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package wasmbustest
22

33
import (
4-
"testing"
54
"time"
65

76
"github.com/nats-io/nats-server/v2/server"
87
"github.com/nats-io/nats.go"
98
)
109

11-
func MustStartNats(t *testing.T) func() {
10+
func MustStartNats(t TestingT) func() {
1211
t.Helper()
1312

1413
opts := &server.Options{

0 commit comments

Comments
 (0)