Skip to content

Commit

Permalink
Add test for createJudge
Browse files Browse the repository at this point in the history
  • Loading branch information
akamya997 authored Jul 26, 2024
1 parent 40d7431 commit a116a65
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions services/judge/judge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit a116a65

Please sign in to comment.