2018-02-12 23:22:41 +00:00
|
|
|
package manta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
2019-01-09 00:48:57 +00:00
|
|
|
triton "github.com/joyent/triton-go"
|
2018-02-12 23:22:41 +00:00
|
|
|
"github.com/joyent/triton-go/authentication"
|
2018-02-14 15:39:52 +00:00
|
|
|
tt "github.com/joyent/triton-go/errors"
|
2018-02-12 23:22:41 +00:00
|
|
|
"github.com/joyent/triton-go/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMantaBackend(t *testing.T) {
|
|
|
|
user := os.Getenv("MANTA_USER")
|
|
|
|
keyId := os.Getenv("MANTA_KEY_ID")
|
|
|
|
url := "https://us-east.manta.joyent.com"
|
|
|
|
testHarnessBucket := fmt.Sprintf("test-bucket-%d", randInt())
|
|
|
|
|
|
|
|
if user == "" || keyId == "" {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
input := authentication.SSHAgentSignerInput{
|
|
|
|
KeyID: keyId,
|
|
|
|
AccountName: user,
|
|
|
|
Username: "",
|
|
|
|
}
|
|
|
|
signer, err := authentication.NewSSHAgentSigner(input)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error Creating SSH Agent Signer: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
config := &triton.ClientConfig{
|
|
|
|
MantaURL: url,
|
|
|
|
AccountName: user,
|
|
|
|
Signers: []authentication.Signer{signer},
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := storage.NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed initialising Storage client: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
logger := logging.NewVaultLogger(log.Debug)
|
2018-02-12 23:22:41 +00:00
|
|
|
mb := &MantaBackend{
|
|
|
|
client: client,
|
|
|
|
directory: testHarnessBucket,
|
2018-04-03 00:46:59 +00:00
|
|
|
logger: logger.Named("storage.mantabackend"),
|
2018-02-12 23:22:41 +00:00
|
|
|
permitPool: physical.NewPermitPool(128),
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mb.client.Dir().Put(context.Background(), &storage.PutDirectoryInput{
|
|
|
|
DirectoryName: path.Join(mantaDefaultRootStore),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Error creating test harness directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
err = mb.client.Dir().Delete(context.Background(), &storage.DeleteDirectoryInput{
|
|
|
|
DirectoryName: path.Join(mantaDefaultRootStore, testHarnessBucket),
|
|
|
|
ForceDelete: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2018-02-14 15:39:52 +00:00
|
|
|
if !tt.IsResourceNotFoundError(err) {
|
2018-02-12 23:22:41 +00:00
|
|
|
t.Fatal("failed to delete test harness directory")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
physical.ExerciseBackend(t, mb)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, mb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func randInt() int {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
return rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
|
|
|
}
|