open-vault/physical/manta/manta_test.go
Becca Petrin 03cf302e9a Move to "github.com/hashicorp/go-hclog" (#4227)
* logbridge with hclog and identical output

* Initial search & replace

This compiles, but there is a fair amount of TODO
and commented out code, especially around the
plugin logclient/logserver code.

* strip logbridge

* fix majority of tests

* update logxi aliases

* WIP fixing tests

* more test fixes

* Update test to hclog

* Fix format

* Rename hclog -> log

* WIP making hclog and logxi love each other

* update logger_test.go

* clean up merged comments

* Replace RawLogger interface with a Logger

* Add some logger names

* Replace Trace with Debug

* update builtin logical logging patterns

* Fix build errors

* More log updates

* update log approach in command and builtin

* More log updates

* update helper, http, and logical directories

* Update loggers

* Log updates

* Update logging

* Update logging

* Update logging

* Update logging

* update logging in physical

* prefixing and lowercase

* Update logging

* Move phyisical logging name to server command

* Fix som tests

* address jims feedback so far

* incorporate brians feedback so far

* strip comments

* move vault.go to logging package

* update Debug to Trace

* Update go-plugin deps

* Update logging based on review comments

* Updates from review

* Unvendor logxi

* Remove null_logger.go
2018-04-02 17:46:59 -07:00

87 lines
2 KiB
Go

package manta
import (
"context"
"fmt"
"math/rand"
"os"
"path"
"testing"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/physical"
"github.com/joyent/triton-go"
"github.com/joyent/triton-go/authentication"
tt "github.com/joyent/triton-go/errors"
"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())
}
logger := logging.NewVaultLogger(log.Debug)
mb := &MantaBackend{
client: client,
directory: testHarnessBucket,
logger: logger.Named("storage.mantabackend"),
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 {
if !tt.IsResourceNotFoundError(err) {
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()
}