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