2017-08-03 17:24:27 +00:00
|
|
|
package mssql
|
2017-04-06 13:33:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/helper/logformat"
|
2017-08-03 17:24:27 +00:00
|
|
|
"github.com/hashicorp/vault/physical"
|
2017-04-06 13:33:49 +00:00
|
|
|
log "github.com/mgutz/logxi/v1"
|
|
|
|
|
|
|
|
_ "github.com/denisenkom/go-mssqldb"
|
|
|
|
)
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
func TestMSSQLBackend(t *testing.T) {
|
2017-04-06 13:33:49 +00:00
|
|
|
server := os.Getenv("MSSQL_SERVER")
|
|
|
|
if server == "" {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
database := os.Getenv("MSSQL_DB")
|
|
|
|
if database == "" {
|
|
|
|
database = "test"
|
|
|
|
}
|
|
|
|
|
|
|
|
table := os.Getenv("MSSQL_TABLE")
|
|
|
|
if table == "" {
|
|
|
|
table = "test"
|
|
|
|
}
|
|
|
|
|
|
|
|
username := os.Getenv("MSSQL_USERNAME")
|
|
|
|
password := os.Getenv("MSSQL_PASSWORD")
|
|
|
|
|
|
|
|
// Run vault tests
|
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
b, err := NewMSSQLBackend(map[string]string{
|
2017-04-06 13:33:49 +00:00
|
|
|
"server": server,
|
|
|
|
"database": database,
|
|
|
|
"table": table,
|
|
|
|
"username": username,
|
|
|
|
"password": password,
|
2017-08-03 17:24:27 +00:00
|
|
|
}, logger)
|
2017-04-06 13:33:49 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create new backend: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2017-08-03 17:24:27 +00:00
|
|
|
mssql := b.(*MSSQLBackend)
|
2017-04-06 13:33:49 +00:00
|
|
|
_, err := mssql.client.Exec("DROP TABLE " + mssql.dbTable)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to drop table: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
physical.ExerciseBackend(t, b)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, b)
|
2017-04-06 13:33:49 +00:00
|
|
|
}
|