80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package judge
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MockJudge struct {
|
||
|
|
name string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (mj *MockJudge) Name() string {
|
||
|
|
return mj.name
|
||
|
|
}
|
||
|
|
|
||
|
|
func (mj *MockJudge) Judge(taskID string, input map[string]interface{}) (map[string]interface{}, error) {
|
||
|
|
return map[string]interface{}{"approved": true}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (mj *MockJudge) Validate() error {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestRegisterJudge(t *testing.T) {
|
||
|
|
registry := NewCustomJudgeRegistry()
|
||
|
|
judge := &MockJudge{name: "security-auditor"}
|
||
|
|
|
||
|
|
err := registry.Register("security-auditor", judge)
|
||
|
|
assert.NoError(t, err)
|
||
|
|
|
||
|
|
retrieved, exists := registry.Get("security-auditor")
|
||
|
|
assert.True(t, exists)
|
||
|
|
assert.Equal(t, "security-auditor", retrieved.Name())
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestJudge(t *testing.T) {
|
||
|
|
registry := NewCustomJudgeRegistry()
|
||
|
|
judge := &MockJudge{name: "security-auditor"}
|
||
|
|
|
||
|
|
registry.Register("security-auditor", judge)
|
||
|
|
result, err := registry.Judge("security-auditor", "T0.1", map[string]interface{}{})
|
||
|
|
|
||
|
|
assert.NoError(t, err)
|
||
|
|
approved, ok := result["approved"].(bool)
|
||
|
|
assert.True(t, ok)
|
||
|
|
assert.True(t, approved)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestListJudges(t *testing.T) {
|
||
|
|
registry := NewCustomJudgeRegistry()
|
||
|
|
|
||
|
|
for i := 0; i < 3; i++ {
|
||
|
|
registry.Register("judge-"+string(rune(48+i)), &MockJudge{})
|
||
|
|
}
|
||
|
|
|
||
|
|
judges := registry.ListJudges()
|
||
|
|
assert.Equal(t, 3, len(judges))
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestSetDefault(t *testing.T) {
|
||
|
|
registry := NewCustomJudgeRegistry()
|
||
|
|
judge := &MockJudge{name: "default"}
|
||
|
|
|
||
|
|
registry.SetDefaultJudge(judge)
|
||
|
|
assert.NotNil(t, registry.GetDefaultJudge())
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestUnregister(t *testing.T) {
|
||
|
|
registry := NewCustomJudgeRegistry()
|
||
|
|
judge := &MockJudge{name: "test"}
|
||
|
|
|
||
|
|
registry.Register("test", judge)
|
||
|
|
err := registry.Unregister("test")
|
||
|
|
|
||
|
|
assert.NoError(t, err)
|
||
|
|
_, exists := registry.Get("test")
|
||
|
|
assert.False(t, exists)
|
||
|
|
}
|