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

attachment_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package attachment
  4. import (
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/models/db"
  9. repo_model "code.gitea.io/gitea/models/repo"
  10. "code.gitea.io/gitea/models/unittest"
  11. user_model "code.gitea.io/gitea/models/user"
  12. _ "code.gitea.io/gitea/models/actions"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestMain(m *testing.M) {
  16. unittest.MainTest(m)
  17. }
  18. func TestUploadAttachment(t *testing.T) {
  19. assert.NoError(t, unittest.PrepareTestDatabase())
  20. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
  21. fPath := "./attachment_test.go"
  22. f, err := os.Open(fPath)
  23. assert.NoError(t, err)
  24. defer f.Close()
  25. attach, err := NewAttachment(&repo_model.Attachment{
  26. RepoID: 1,
  27. UploaderID: user.ID,
  28. Name: filepath.Base(fPath),
  29. }, f, -1)
  30. assert.NoError(t, err)
  31. attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attach.UUID)
  32. assert.NoError(t, err)
  33. assert.EqualValues(t, user.ID, attachment.UploaderID)
  34. assert.Equal(t, int64(0), attachment.DownloadCount)
  35. }