diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-16 21:51:17 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-16 21:51:17 +0900 |
| commit | 08c121c21a7e429e43e2d51fa4a3d8bd945c5d01 (patch) | |
| tree | 6912af4982952945d5c3402fb748ac09e63993cd /backend/taskqueue/processor_test.go | |
| parent | 946ba064bcf625e32faf1f202e243fa6b2aa8e27 (diff) | |
| download | phperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.tar.gz phperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.tar.zst phperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.zip | |
test(backend): add unit tests for admin handlers and taskqueue
Add comprehensive tests for previously untested packages:
- admin: middleware auth checks, CRUD handlers for users/games/problems/testcases
- taskqueue: task creation, payload serialization, code hash calculation
- api: expose SetUserInContext helper for cross-package test support
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'backend/taskqueue/processor_test.go')
| -rw-r--r-- | backend/taskqueue/processor_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/backend/taskqueue/processor_test.go b/backend/taskqueue/processor_test.go new file mode 100644 index 0000000..3646b4c --- /dev/null +++ b/backend/taskqueue/processor_test.go @@ -0,0 +1,41 @@ +package taskqueue + +import ( + "testing" +) + +func TestCalcCodeHash(t *testing.T) { + // Same code + same testcaseID should produce same hash + hash1 := calcCodeHash("echo hello", 1) + hash2 := calcCodeHash("echo hello", 1) + if hash1 != hash2 { + t.Errorf("same input produced different hashes: %q vs %q", hash1, hash2) + } + + // Different code should produce different hash + hash3 := calcCodeHash("echo world", 1) + if hash1 == hash3 { + t.Errorf("different code produced same hash: %q", hash1) + } + + // Different testcaseID should produce different hash + hash4 := calcCodeHash("echo hello", 2) + if hash1 == hash4 { + t.Errorf("different testcaseID produced same hash: %q", hash1) + } + + // Hash should be a valid hex md5 (32 characters) + if len(hash1) != 32 { + t.Errorf("hash length = %d, want 32", len(hash1)) + } +} + +func TestCalcCodeHash_EmptyCode(t *testing.T) { + hash := calcCodeHash("", 0) + if hash == "" { + t.Error("hash should not be empty for empty code") + } + if len(hash) != 32 { + t.Errorf("hash length = %d, want 32", len(hash)) + } +} |
