From ea4173406e2804dd1a0dce071125eccd67ecb6dd Mon Sep 17 00:00:00 2001 From: Brian Kassouf Date: Thu, 13 Apr 2017 14:30:15 -0700 Subject: [PATCH] Move mssql to be an acceptance test --- plugins/database/mssql/mssql_test.go | 62 +++++++--------------------- 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/plugins/database/mssql/mssql_test.go b/plugins/database/mssql/mssql_test.go index bc182f26fd..2bca0a7b85 100644 --- a/plugins/database/mssql/mssql_test.go +++ b/plugins/database/mssql/mssql_test.go @@ -11,56 +11,17 @@ import ( "github.com/hashicorp/vault/builtin/logical/database/dbplugin" "github.com/hashicorp/vault/plugins/helper/database/connutil" - dockertest "gopkg.in/ory-am/dockertest.v3" ) var ( testMSQLImagePull sync.Once ) -func prepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) { - if os.Getenv("MSSQL_URL") != "" { - return func() {}, os.Getenv("MSSQL_URL") - } - - pool, err := dockertest.NewPool("") - if err != nil { - t.Fatalf("Failed to connect to docker: %s", err) - } - - resource, err := pool.Run("microsoft/mssql-server-linux", "latest", []string{"ACCEPT_EULA=Y", "SA_PASSWORD=yourStrong(!)Password"}) - if err != nil { - t.Fatalf("Could not start local MSSQL docker container: %s", err) - } - - cleanup = func() { - err := pool.Purge(resource) - if err != nil { - t.Fatalf("Failed to cleanup local container: %s", err) - } - } - - retURL = fmt.Sprintf("sqlserver://sa:yourStrong(!)Password@localhost:%s", resource.GetPort("1433/tcp")) - - // exponential backoff-retry - if err = pool.Retry(func() error { - var err error - var db *sql.DB - db, err = sql.Open("mssql", retURL) - if err != nil { - return err - } - return db.Ping() - }); err != nil { - t.Fatalf("Could not connect to MSSQL docker container: %s", err) - } - - return -} - func TestMSSQL_Initialize(t *testing.T) { - cleanup, connURL := prepareMSSQLTestContainer(t) - defer cleanup() + if os.Getenv("MSSQL_URL") == "" { + return + } + connURL := os.Getenv("MSSQL_URL") connectionDetails := map[string]interface{}{ "connection_url": connURL, @@ -85,8 +46,10 @@ func TestMSSQL_Initialize(t *testing.T) { } func TestMSSQL_CreateUser(t *testing.T) { - cleanup, connURL := prepareMSSQLTestContainer(t) - defer cleanup() + if os.Getenv("MSSQL_URL") == "" { + return + } + connURL := os.Getenv("MSSQL_URL") connectionDetails := map[string]interface{}{ "connection_url": connURL, @@ -119,8 +82,10 @@ func TestMSSQL_CreateUser(t *testing.T) { } func TestMSSQL_RevokeUser(t *testing.T) { - cleanup, connURL := prepareMSSQLTestContainer(t) - defer cleanup() + if os.Getenv("MSSQL_URL") == "" { + return + } + connURL := os.Getenv("MSSQL_URL") connectionDetails := map[string]interface{}{ "connection_url": connURL, @@ -158,7 +123,8 @@ func TestMSSQL_RevokeUser(t *testing.T) { func testCredsExist(t testing.TB, connURL, username, password string) error { // Log in with the new creds - connURL = strings.Replace(connURL, "sa:yourStrong(!)Password", fmt.Sprintf("%s:%s", username, password), 1) + parts := strings.Split(connURL, "@") + connURL = fmt.Sprintf("sqlserver://%s:%s@%s", username, password, parts[1]) db, err := sql.Open("mssql", connURL) if err != nil { return err