Browse Source

fix test

tags/vopendata0.1.2
Lunny Xiao yan 5 years ago
parent
commit
379b46b30b
2 changed files with 9 additions and 3 deletions
  1. +2
    -1
      integrations/attachment_test.go
  2. +7
    -2
      models/attachment.go

+ 2
- 1
integrations/attachment_test.go View File

@@ -14,6 +14,7 @@ import (
"strings"
"testing"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/test"

@@ -121,7 +122,7 @@ func TestGetAttachment(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
//Write empty file to be available for response
if tc.createFile {
err = storage.Attachments.Save(tc.RelativePath(), strings.NewReader("hello world"))
_, err := storage.Attachments.Save(models.AttachmentRelativePath(tc), strings.NewReader("hello world"))
assert.NoError(t, err)
}
//Actual test


+ 7
- 2
models/attachment.go View File

@@ -61,9 +61,14 @@ func (a *Attachment) DownloadURL() string {
return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID)
}

// AttachmentRelativePath returns the relative path
func AttachmentRelativePath(uuid string) string {
return path.Join(uuid[0:1], uuid[1:2], uuid)
}

// RelativePath returns the relative path of the attachment
func (a *Attachment) RelativePath() string {
return path.Join(a.UUID[0:1], a.UUID[1:2], a.UUID)
return AttachmentRelativePath(a.UUID)
}

// LinkedRepository returns the linked repo if any
@@ -288,4 +293,4 @@ func IterateAttachment(f func(attach *Attachment) error) error {
}
}
}
}
}

Loading…
Cancel
Save