You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

attachment_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 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 attachment
  5. import (
  6. "os"
  7. "path/filepath"
  8. "testing"
  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. "github.com/stretchr/testify/assert"
  13. )
  14. func TestMain(m *testing.M) {
  15. unittest.MainTest(m, &unittest.TestOptions{
  16. GiteaRootPath: filepath.Join("..", ".."),
  17. })
  18. }
  19. func TestUploadAttachment(t *testing.T) {
  20. assert.NoError(t, unittest.PrepareTestDatabase())
  21. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
  22. fPath := "./attachment_test.go"
  23. f, err := os.Open(fPath)
  24. assert.NoError(t, err)
  25. defer f.Close()
  26. attach, err := NewAttachment(&repo_model.Attachment{
  27. RepoID: 1,
  28. UploaderID: user.ID,
  29. Name: filepath.Base(fPath),
  30. }, f)
  31. assert.NoError(t, err)
  32. attachment, err := repo_model.GetAttachmentByUUID(attach.UUID)
  33. assert.NoError(t, err)
  34. assert.EqualValues(t, user.ID, attachment.UploaderID)
  35. assert.Equal(t, int64(0), attachment.DownloadCount)
  36. }