aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/swift/models_test.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-16 22:49:07 +0900
committernsfisis <nsfisis@gmail.com>2026-02-16 22:49:07 +0900
commitefe05c1444963c046ab91bf54fa51a794bda58c0 (patch)
tree509b48f27d2e888740bea6bfd6f50895705c7472 /worker/swift/models_test.go
parentdb87f85aa7055e597800481b8cc6d006c70bcc88 (diff)
downloadphperkaigi-2026-albatross-efe05c1444963c046ab91bf54fa51a794bda58c0.tar.gz
phperkaigi-2026-albatross-efe05c1444963c046ab91bf54fa51a794bda58c0.tar.zst
phperkaigi-2026-albatross-efe05c1444963c046ab91bf54fa51a794bda58c0.zip
test(worker): add unit tests for php and swift workers
Extract testable logic from exec.mjs into lib.mjs (preprocessCode, createIOCallbacks, buildResult) and add vitest tests. Add Go tests for models, exec helpers, and handlers in worker/swift. Update justfiles to include test tasks for local dev and CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'worker/swift/models_test.go')
-rw-r--r--worker/swift/models_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/worker/swift/models_test.go b/worker/swift/models_test.go
new file mode 100644
index 0000000..62d6675
--- /dev/null
+++ b/worker/swift/models_test.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "testing"
+ "time"
+)
+
+func TestExecRequestData_Validate(t *testing.T) {
+ tests := []struct {
+ name string
+ maxDurationMs int
+ wantErr error
+ }{
+ {"positive value", 1000, nil},
+ {"zero", 0, errInvalidMaxDuration},
+ {"negative value", -1, errInvalidMaxDuration},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &execRequestData{MaxDurationMilliseconds: tt.maxDurationMs}
+ err := req.validate()
+ if err != tt.wantErr {
+ t.Errorf("validate() = %v, want %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestExecRequestData_MaxDuration(t *testing.T) {
+ tests := []struct {
+ name string
+ maxDurationMs int
+ want time.Duration
+ }{
+ {"1000ms", 1000, 1 * time.Second},
+ {"500ms", 500, 500 * time.Millisecond},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &execRequestData{MaxDurationMilliseconds: tt.maxDurationMs}
+ got := req.maxDuration()
+ if got != tt.want {
+ t.Errorf("maxDuration() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestExecResponseData_Success(t *testing.T) {
+ tests := []struct {
+ name string
+ status string
+ want bool
+ }{
+ {"success", resultSuccess, true},
+ {"compile_error", resultCompileError, false},
+ {"runtime_error", resultRuntimeError, false},
+ {"timeout", resultTimeout, false},
+ {"internal_error", resultInternalError, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ res := &execResponseData{Status: tt.status}
+ got := res.success()
+ if got != tt.want {
+ t.Errorf("success() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}