您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

issue_comment_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestCreateComment(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. issue := AssertExistsAndLoadBean(t, &Issue{}).(*Issue)
  13. repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
  14. doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
  15. now := time.Now().Unix()
  16. comment, err := CreateComment(&CreateCommentOptions{
  17. Type: CommentTypeComment,
  18. Doer: doer,
  19. Repo: repo,
  20. Issue: issue,
  21. Content: "Hello",
  22. })
  23. assert.NoError(t, err)
  24. then := time.Now().Unix()
  25. assert.EqualValues(t, CommentTypeComment, comment.Type)
  26. assert.EqualValues(t, "Hello", comment.Content)
  27. assert.EqualValues(t, issue.ID, comment.IssueID)
  28. assert.EqualValues(t, doer.ID, comment.PosterID)
  29. AssertInt64InRange(t, now, then, int64(comment.CreatedUnix))
  30. AssertExistsAndLoadBean(t, comment) // assert actually added to DB
  31. updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
  32. AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
  33. }