Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-27 12:16:10 +01:00
forgejo/modules/storage/minio_test.go

95 lines
2.8 KiB
Go
Raw Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package storage
import (
"context"
"net/http"
"os"
"testing"
"code.gitea.io/gitea/modules/setting"
"github.com/minio/minio-go/v7"
"github.com/stretchr/testify/assert"
)
func TestMinioStorageIterator(t *testing.T) {
if os.Getenv("CI") == "" {
t.Skip("minioStorage not present outside of CI")
return
}
testStorageIterator(t, setting.MinioStorageType, &setting.Storage{
MinioConfig: setting.MinioStorageConfig{
[CI] Forgejo Actions based CI for PR & branches (cherry picked from commit f9d75d4705ece5c119f2fd5e2bfbaf630d0bf739) (cherry picked from commit 64f76f4ab269daa6a584305164732c68be0161c5) (cherry picked from commit 5d024541551f1be98444923f0fa327a855104725) [CI] Forgejo Actions workflows (cherry picked from commit 3ff59b5379ebf761f32875f9d869a1d18f79741c) (cherry picked from commit 8af826a6f7c70d03079ec68f10230041695017cd) (cherry picked from commit d7c09d9cc80037a28d488da142ae2a2a99f59ac9) [CI] use the docker label instead of ubuntu-latest (cherry picked from commit b6a6470db6c8bae9963e204f9c8c408f309e81e3) [CI] all tests need compliance before proceeding (cherry picked from commit b35c496f2c3034164b9bb3a3550f35026adf9372) (cherry picked from commit 36a4148a8ec654ae9fa5a6925a3b8606b96aebcc) (cherry picked from commit 7ffcffa653808a284f422fdc31f6ea07874b585d) (cherry picked from commit 8a246d296e502c181c6ee779d1773c9e78ca7acf) (cherry picked from commit dd0b6e1826ba7699f967de2c00c1332909a53473) [CI] Forgejo Actions based release process (squash) MySQL optimization Refs: https://codeberg.org/forgejo/forgejo/issues/976 (cherry picked from commit b4b8c489e6e9fe36349eced5d4249467b25df2a7) (cherry picked from commit 1e861db4afdc32549784381a96b16dac508ec1c0) (cherry picked from commit a6c0e00330ded851c2f524039259f0b723d793e4) (cherry picked from commit f97b336465fd6be15079e756c9ee3a580f0aa339) (cherry picked from commit 6d65d5f0d6f798556a8f9e547896be03a5ee2f87) (cherry picked from commit 79bfbadbed3bf84b96f2c027d119a4aa5c60d5e2) (cherry picked from commit e86c40a34a97fc568c724ee5f8ee5b2bf46ebf19) (cherry picked from commit da0c454adbcf1b5dbb95d9d74afaa371e32351a0) (cherry picked from commit b49d892cda968b22ad6c29caade042690d96f2e2) [CI] enable minio tests (cherry picked from commit 4d8f4380311b872061bd20f561424662ecd8d817) (cherry picked from commit c4eeb0a61ef579c21b0382edd61c62adebe93b28) [CI] Forgejo Actions based CI for PR & branches (squash) cleanup (cherry picked from commit 80eb20e84267552c971096693558734f0ec7afdd) (cherry picked from commit d2ff589858961e4f25bc1d903cdf57df1db4c316) (cherry picked from commit f6eedecb67fce992605bb1fcdd93c866ec47a9d4) (cherry picked from commit cf458091e245e1c70944e940a214d5127f304303) (cherry picked from commit ddd322cb2de165126080b222c1b09b2a91fea182) (cherry picked from commit f0f5729b6467bea053d532c4c64c54a0fe737c98) (cherry picked from commit 26641662b6bbb1db761e514795bedb9bdbc36d5e) (cherry picked from commit 4e596bc0028f9329f3196b2e822484c4482ea586) (cherry picked from commit 6ce4ff732e8c1dbe35d854b32ef44cca66bd3fc7) (cherry picked from commit 4db9d5e4f9dd182d8307a15bba7aa4f6aa5e4beb) (cherry picked from commit 8cd3ce255b420d5ac74fa25adb31804c6ac2c976) (cherry picked from commit 3b380c35eb47561183cad75d2e194e8bbf7f8b2b)
2023-05-28 15:31:52 +02:00
Endpoint: "minio:9000",
AccessKeyID: "123456",
SecretAccessKey: "12345678",
Bucket: "gitea",
Location: "us-east-1",
},
})
}
func TestMinioStoragePath(t *testing.T) {
m := &MinioStorage{basePath: ""}
assert.Equal(t, "", m.buildMinioPath("/"))
assert.Equal(t, "", m.buildMinioPath("."))
assert.Equal(t, "a", m.buildMinioPath("/a"))
assert.Equal(t, "a/b", m.buildMinioPath("/a/b/"))
assert.Equal(t, "", m.buildMinioDirPrefix(""))
assert.Equal(t, "a/", m.buildMinioDirPrefix("/a/"))
m = &MinioStorage{basePath: "/"}
assert.Equal(t, "", m.buildMinioPath("/"))
assert.Equal(t, "", m.buildMinioPath("."))
assert.Equal(t, "a", m.buildMinioPath("/a"))
assert.Equal(t, "a/b", m.buildMinioPath("/a/b/"))
assert.Equal(t, "", m.buildMinioDirPrefix(""))
assert.Equal(t, "a/", m.buildMinioDirPrefix("/a/"))
m = &MinioStorage{basePath: "/base"}
assert.Equal(t, "base", m.buildMinioPath("/"))
assert.Equal(t, "base", m.buildMinioPath("."))
assert.Equal(t, "base/a", m.buildMinioPath("/a"))
assert.Equal(t, "base/a/b", m.buildMinioPath("/a/b/"))
assert.Equal(t, "base/", m.buildMinioDirPrefix(""))
assert.Equal(t, "base/a/", m.buildMinioDirPrefix("/a/"))
m = &MinioStorage{basePath: "/base/"}
assert.Equal(t, "base", m.buildMinioPath("/"))
assert.Equal(t, "base", m.buildMinioPath("."))
assert.Equal(t, "base/a", m.buildMinioPath("/a"))
assert.Equal(t, "base/a/b", m.buildMinioPath("/a/b/"))
assert.Equal(t, "base/", m.buildMinioDirPrefix(""))
assert.Equal(t, "base/a/", m.buildMinioDirPrefix("/a/"))
}
func TestS3StorageBadRequest(t *testing.T) {
if os.Getenv("CI") == "" {
t.Skip("S3Storage not present outside of CI")
return
}
cfg := &setting.Storage{
MinioConfig: setting.MinioStorageConfig{
Endpoint: "minio:9000",
AccessKeyID: "123456",
SecretAccessKey: "12345678",
Bucket: "bucket",
Location: "us-east-1",
},
}
message := "ERROR"
old := getBucketVersioning
defer func() { getBucketVersioning = old }()
getBucketVersioning = func(ctx context.Context, minioClient *minio.Client, bucket string) error {
return minio.ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "FixtureError",
Message: message,
}
}
_, err := NewStorage(setting.MinioStorageType, cfg)
assert.ErrorContains(t, err, message)
}