mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-12 05:23:45 +08:00
fb7b743bd0
This PR implemented object storages(LFS/Packages/Attachments and etc.) for Azure Blob Storage. It depends on azure official golang SDK and can support both the azure blob storage cloud service and azurite mock server. Replace #25458 Fix #22527 - [x] CI Tests - [x] integration test, MSSQL integration tests will now based on azureblob - [x] unit test - [x] CLI Migrate Storage - [x] Documentation for configuration added ------ TODO (other PRs): - [ ] Improve performance of `blob download`. --------- Co-authored-by: yp05327 <576951401@qq.com>
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package storage
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAzureBlobStorageIterator(t *testing.T) {
|
|
if os.Getenv("CI") == "" {
|
|
t.Skip("azureBlobStorage not present outside of CI")
|
|
return
|
|
}
|
|
testStorageIterator(t, setting.AzureBlobStorageType, &setting.Storage{
|
|
AzureBlobConfig: setting.AzureBlobStorageConfig{
|
|
// https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio-code#ip-style-url
|
|
Endpoint: "http://devstoreaccount1.azurite.local:10000",
|
|
// https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio-code#well-known-storage-account-and-key
|
|
AccountName: "devstoreaccount1",
|
|
AccountKey: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
|
|
Container: "test",
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAzureBlobStoragePath(t *testing.T) {
|
|
m := &AzureBlobStorage{cfg: &setting.AzureBlobStorageConfig{BasePath: ""}}
|
|
assert.Equal(t, "", m.buildAzureBlobPath("/"))
|
|
assert.Equal(t, "", m.buildAzureBlobPath("."))
|
|
assert.Equal(t, "a", m.buildAzureBlobPath("/a"))
|
|
assert.Equal(t, "a/b", m.buildAzureBlobPath("/a/b/"))
|
|
|
|
m = &AzureBlobStorage{cfg: &setting.AzureBlobStorageConfig{BasePath: "/"}}
|
|
assert.Equal(t, "", m.buildAzureBlobPath("/"))
|
|
assert.Equal(t, "", m.buildAzureBlobPath("."))
|
|
assert.Equal(t, "a", m.buildAzureBlobPath("/a"))
|
|
assert.Equal(t, "a/b", m.buildAzureBlobPath("/a/b/"))
|
|
|
|
m = &AzureBlobStorage{cfg: &setting.AzureBlobStorageConfig{BasePath: "/base"}}
|
|
assert.Equal(t, "base", m.buildAzureBlobPath("/"))
|
|
assert.Equal(t, "base", m.buildAzureBlobPath("."))
|
|
assert.Equal(t, "base/a", m.buildAzureBlobPath("/a"))
|
|
assert.Equal(t, "base/a/b", m.buildAzureBlobPath("/a/b/"))
|
|
|
|
m = &AzureBlobStorage{cfg: &setting.AzureBlobStorageConfig{BasePath: "/base/"}}
|
|
assert.Equal(t, "base", m.buildAzureBlobPath("/"))
|
|
assert.Equal(t, "base", m.buildAzureBlobPath("."))
|
|
assert.Equal(t, "base/a", m.buildAzureBlobPath("/a"))
|
|
assert.Equal(t, "base/a/b", m.buildAzureBlobPath("/a/b/"))
|
|
}
|