2014-11-25 19:40:24 +01:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-08-24 13:18:39 +02:00
|
|
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
|
|
|
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
2014-11-25 19:40:24 +01:00
|
|
|
. "gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
envAccountName = "AZURE_STORAGE_ACCOUNT_NAME"
|
|
|
|
envAccountKey = "AZURE_STORAGE_ACCOUNT_KEY"
|
|
|
|
envContainer = "AZURE_STORAGE_CONTAINER"
|
2015-03-24 02:20:06 +01:00
|
|
|
envRealm = "AZURE_STORAGE_REALM"
|
2014-11-25 19:40:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hook up gocheck into the "go test" runner.
|
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var (
|
|
|
|
accountName string
|
|
|
|
accountKey string
|
|
|
|
container string
|
2015-03-24 02:20:06 +01:00
|
|
|
realm string
|
2014-11-25 19:40:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
config := []struct {
|
|
|
|
env string
|
|
|
|
value *string
|
|
|
|
}{
|
|
|
|
{envAccountName, &accountName},
|
|
|
|
{envAccountKey, &accountKey},
|
|
|
|
{envContainer, &container},
|
2015-03-24 02:20:06 +01:00
|
|
|
{envRealm, &realm},
|
2014-11-25 19:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
missing := []string{}
|
|
|
|
for _, v := range config {
|
|
|
|
*v.value = os.Getenv(v.env)
|
|
|
|
if *v.value == "" {
|
|
|
|
missing = append(missing, v.env)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
azureDriverConstructor := func() (storagedriver.StorageDriver, error) {
|
2015-03-24 02:20:06 +01:00
|
|
|
return New(accountName, accountKey, container, realm)
|
2014-11-25 19:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip Azure storage driver tests if environment variable parameters are not provided
|
|
|
|
skipCheck := func() string {
|
|
|
|
if len(missing) > 0 {
|
|
|
|
return fmt.Sprintf("Must set %s environment variables to run Azure tests", strings.Join(missing, ", "))
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-06-30 01:39:45 +02:00
|
|
|
testsuites.RegisterSuite(azureDriverConstructor, skipCheck)
|
2014-11-25 19:40:24 +01:00
|
|
|
}
|