mirror of https://github.com/grafana/grafana
imguploader: Add support for new internal image store (#6922)
parent
77b5dee408
commit
c82e23d96e
@ -0,0 +1,22 @@ |
||||
package imguploader |
||||
|
||||
import ( |
||||
"context" |
||||
"path" |
||||
"path/filepath" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
type LocalUploader struct { |
||||
} |
||||
|
||||
func (u *LocalUploader) Upload(ctx context.Context, imageOnDiskPath string) (string, error) { |
||||
filename := filepath.Base(imageOnDiskPath) |
||||
image_url := setting.ToAbsUrl(path.Join("public/img/attachments", filename)) |
||||
return image_url, nil |
||||
} |
||||
|
||||
func NewLocalImageUploader() (*LocalUploader, error) { |
||||
return &LocalUploader{}, nil |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
package imguploader |
||||
|
||||
import ( |
||||
"context" |
||||
"testing" |
||||
|
||||
. "github.com/smartystreets/goconvey/convey" |
||||
) |
||||
|
||||
func TestUploadToLocal(t *testing.T) { |
||||
Convey("[Integration test] for external_image_store.local", t, func() { |
||||
localUploader, _ := NewLocalImageUploader() |
||||
path, err := localUploader.Upload(context.Background(), "../../../public/img/logo_transparent_400x.png") |
||||
|
||||
So(err, ShouldBeNil) |
||||
So(path, ShouldContainSubstring, "/public/img/attachments") |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue