diff --git a/services/judge/judge_test.go b/services/judge/judge_test.go index 6f2bb8e..7c38d85 100644 --- a/services/judge/judge_test.go +++ b/services/judge/judge_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/gin-gonic/gin" + "github.com/oj-lab/oj-lab-platform/models" judge_model "github.com/oj-lab/oj-lab-platform/models/judge" problem_model "github.com/oj-lab/oj-lab-platform/models/problem" gorm_agent "github.com/oj-lab/oj-lab-platform/modules/agent/gorm" @@ -40,3 +41,28 @@ func TestGetJudge(t *testing.T) { asserts.Equal(judge.ProblemSlug, response_judge.ProblemSlug) asserts.Equal(judge.Language, response_judge.Language) } + +func TestCreateJudge(t *testing.T) { + ctx, _ := gin.CreateTestContext(httptest.NewRecorder()) + judge := &judge_model.Judge{ + Language: judge_model.ProgrammingLanguageCpp, + ProblemSlug: "test-judge-service", + } + _, err := CreateJudge(ctx, *judge) + if err != nil { + t.Error(err) + } + + db := gorm_agent.GetDefaultDB() + judges, _, err := judge_model.GetJudgeListByOptions(db, judge_model.GetJudgeOptions{OrderByColumns: []models.OrderByColumnOption{{Column: "create_at", Desc: true}}}) + if err != nil || len(judges) == 0 { + t.Error(err) + } + insert_judge, err := judge_model.GetJudge(db, judges[0].UID) + if err != nil { + t.Error(err) + } + asserts := assert.New(t) + asserts.Equal(judge.ProblemSlug, insert_judge.ProblemSlug) + asserts.Equal(judge.Language, insert_judge.Language) +}