Merge pull request #127 from sgotti/tests_wait_gitea_ready

tests: wait gitea ready
This commit is contained in:
Simone Gotti 2019-09-30 12:00:12 +02:00 committed by GitHub
commit 9b28031ccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 4 deletions

View File

@ -93,11 +93,32 @@ func setupGitea(t *testing.T, dir, dockerBridgeAddress string) *testutil.TestGit
if err := tgitea.Start(); err != nil { if err := tgitea.Start(); err != nil {
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }
time.Sleep(5 * time.Second)
// wait for gitea ready
err = testutil.Wait(30*time.Second, func() (bool, error) {
cmd := exec.Command(tgitea.GiteaPath, "admin", "create-user", "--name", giteaUser01, "--email", giteaUser01+"@example.com", "--password", "password", "--admin", "--config", tgitea.ConfigPath) cmd := exec.Command(tgitea.GiteaPath, "admin", "create-user", "--name", giteaUser01, "--email", giteaUser01+"@example.com", "--password", "password", "--admin", "--config", tgitea.ConfigPath)
if out, err := cmd.CombinedOutput(); err != nil { // just retry until no error
t.Fatalf("unexpected err: %v, out: %s", err, out) if err := cmd.Run(); err != nil {
return false, nil
}
return true, nil
})
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.HTTPListenAddress, tgitea.HTTPPort)
giteaClient := gitea.NewClient(giteaAPIURL, "")
// Wait for gitea api to be ready
err = testutil.Wait(30*time.Second, func() (bool, error) {
if _, err := giteaClient.ListAccessTokens(giteaUser01, "password"); err != nil {
return false, nil
}
return true, nil
})
if err != nil {
t.Fatalf("unexpected err: %v", err)
} }
return tgitea return tgitea