-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into auto-to-shamir
Showing
63 changed files
with
1,310 additions
and
9,167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package mysqlhelper | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/helper/testhelpers/docker" | ||
"github.com/ory/dockertest" | ||
) | ||
|
||
func PrepareMySQLTestContainer(t *testing.T, legacy bool, pw string) (cleanup func(), retURL string) { | ||
if os.Getenv("MYSQL_URL") != "" { | ||
return func() {}, os.Getenv("MYSQL_URL") | ||
} | ||
|
||
pool, err := dockertest.NewPool("") | ||
if err != nil { | ||
t.Fatalf("Failed to connect to docker: %s", err) | ||
} | ||
|
||
imageVersion := "5.7" | ||
if legacy { | ||
imageVersion = "5.6" | ||
} | ||
|
||
resource, err := pool.Run("mysql", imageVersion, []string{"MYSQL_ROOT_PASSWORD=" + pw}) | ||
if err != nil { | ||
t.Fatalf("Could not start local MySQL docker container: %s", err) | ||
} | ||
|
||
cleanup = func() { | ||
docker.CleanupResource(t, pool, resource) | ||
} | ||
|
||
retURL = fmt.Sprintf("root:%s@(localhost:%s)/mysql?parseTime=true", pw, resource.GetPort("3306/tcp")) | ||
|
||
// exponential backoff-retry | ||
if err = pool.Retry(func() error { | ||
var err error | ||
var db *sql.DB | ||
db, err = sql.Open("mysql", retURL) | ||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
return db.Ping() | ||
}); err != nil { | ||
cleanup() | ||
t.Fatalf("Could not connect to MySQL docker container: %s", err) | ||
} | ||
|
||
return | ||
} | ||
|
||
func TestCredsExist(t testing.TB, connURL, username, password string) error { | ||
// Log in with the new creds | ||
connURL = strings.Replace(connURL, "root:secret", fmt.Sprintf("%s:%s", username, password), 1) | ||
db, err := sql.Open("mysql", connURL) | ||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
return db.Ping() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.