Skip to content

Commit

Permalink
fix: restore the test
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke committed Nov 16, 2024
1 parent d85fb1b commit 7a7f07a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scheduler/plugin/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wasm
import (
"bytes"
"context"
"encoding/json"
"testing"

"github.com/tetratelabs/wazero/experimental/wazerotest"
Expand Down Expand Up @@ -95,6 +96,42 @@ func initKlog(t *testing.T, buf *bytes.Buffer) {
klog.SetOutput(buf)
}

func Test_k8sHandleEventRecorderEventFn(t *testing.T) {
recorder := &test.FakeRecorder{EventMsg: ""}
handle := &test.FakeHandle{Recorder: recorder}
h := host{handle: handle}

// Create a fake wasm module, which has data the guest should write.
mem := wazerotest.NewMemory(wazerotest.PageSize)
mod := wazerotest.NewModule(mem)
message := EventMessage{
RegardingReference: ObjectReference{},
RelatedReference: ObjectReference{},
Eventtype: "event",
Reason: "reason",
Action: "action",
Note: "note",
}
jsonmsg, err := json.Marshal(message)
if err != nil {
t.Fatalf("error during json.Marshal %v", err)
}
copy(mem.Bytes, jsonmsg)

// Invoke the host function in the same way the guest would have.
h.k8sHandleEventRecorderEventfFn(context.Background(), mod, []uint64{
0,
uint64(len(jsonmsg)),
})

have := recorder.EventMsg
want := "event reason action note"

if want != have {
t.Fatalf("unexpected event: %v != %v", want, have)
}
}

func Test_k8sHandleGetWaitingPodFn(t *testing.T) {
recorder := &test.FakeRecorder{EventMsg: ""}
handle := &test.FakeHandle{Recorder: recorder}
Expand Down

0 comments on commit 7a7f07a

Please sign in to comment.