@@ -636,6 +636,9 @@ func TestPutExamToDatabase(t *testing.T) {
636636 examInfoSHA256 , err := courseExamInfoHash (exams )
637637 assert .NoError (t , err )
638638
639+ oldExamInfo := `[{"name":"数据结构","teacher":"张老师","credit":"4.0","exam_time":"旧时间"},{"name":"高等数学","teacher":"李老师","credit":"5.0","exam_time":"旧时间2"}]`
640+ oldExamInfoSHA256 := "old-sha256"
641+
639642 type testCase struct {
640643 name string
641644 rawCourses []* jwch.Course
@@ -658,7 +661,7 @@ func TestPutExamToDatabase(t *testing.T) {
658661 },
659662 {
660663 name : "unchanged exam snapshot is not updated" ,
661- oldCourse : & dbmodel.UserCourse {Id : 1 , ExamInfoSHA256 : examInfoSHA256 },
664+ oldCourse : & dbmodel.UserCourse {Id : 1 , ExamInfoSHA256 : & examInfoSHA256 },
662665 expectUpdate : false ,
663666 expectEnqueue : 0 ,
664667 },
@@ -675,8 +678,8 @@ func TestPutExamToDatabase(t *testing.T) {
675678 },
676679 oldCourse : & dbmodel.UserCourse {
677680 Id : 1 ,
678- ExamInfo : `[{"name":"数据结构","teacher":"张老师","credit":"4.0","exam_time":"旧时间"},{"name":"高等数学","teacher":"李老师","credit":"5.0","exam_time":"旧时间2"}]` ,
679- ExamInfoSHA256 : "old-sha256" ,
681+ ExamInfo : & oldExamInfo ,
682+ ExamInfoSHA256 : & oldExamInfoSHA256 ,
680683 },
681684 expectUpdate : true ,
682685 expectEnqueue : 2 ,
@@ -731,11 +734,15 @@ func TestPutExamToDatabase(t *testing.T) {
731734 assert .NotNil (t , updatedCourse )
732735 assert .Equal (t , int64 (1 ), updatedCourse .Id )
733736 if tc .expectExamInfo != "" {
734- assert .Equal (t , tc .expectExamInfo , updatedCourse .ExamInfo )
735- assert .Equal (t , tc .expectExamHash , updatedCourse .ExamInfoSHA256 )
737+ assert .NotNil (t , updatedCourse .ExamInfo )
738+ assert .Equal (t , tc .expectExamInfo , * updatedCourse .ExamInfo )
739+ assert .NotNil (t , updatedCourse .ExamInfoSHA256 )
740+ assert .Equal (t , tc .expectExamHash , * updatedCourse .ExamInfoSHA256 )
736741 } else {
737- assert .NotEmpty (t , updatedCourse .ExamInfo )
738- assert .NotEmpty (t , updatedCourse .ExamInfoSHA256 )
742+ assert .NotNil (t , updatedCourse .ExamInfo )
743+ assert .NotEmpty (t , * updatedCourse .ExamInfo )
744+ assert .NotNil (t , updatedCourse .ExamInfoSHA256 )
745+ assert .NotEmpty (t , * updatedCourse .ExamInfoSHA256 )
739746 }
740747 })
741748 }
0 commit comments