-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic integration test with Kibana (#493)
This is a simple integration test to validate changes made against the registry are still working with the current version of Kibana.
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build integration | ||
|
||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/magefile/mage/sh" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestSetup tests if Kibana can be run against the current registry | ||
// and the setup command works as expected. | ||
func TestSetup(t *testing.T) { | ||
|
||
currentDir, err := os.Getwd() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer os.Chdir(currentDir) | ||
err = os.Chdir("testing/environments") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Make sure services are shut down again at the end of the test | ||
defer func() { | ||
err = sh.Run("docker-compose", "-f", "snapshot.yml", "-f", "local.yml", "down", "-v") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
}() | ||
// Spin up services | ||
go func() { | ||
err = sh.Run("docker-compose", "-f", "snapshot.yml", "pull") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = sh.Run("docker-compose", "-f", "snapshot.yml", "-f", "local.yml", "up", "--force-recreate", "--remove-orphans", "--build") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
// Check for 5 minutes if service is available | ||
for i := 0; i < 5*60; i++ { | ||
output, _ := sh.Output("docker-compose", "-f", "snapshot.yml", "-f", "local.yml", "ps") | ||
if err != nil { | ||
// Log errors but do not act on it as at first it might not be ready yet | ||
log.Println(err) | ||
} | ||
// 3 services must report healthy | ||
c := strings.Count(output, "healthy") | ||
if c == 3 { | ||
break | ||
} | ||
|
||
// Wait 1 second between each iteration | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
// Run setup in ingest_manager against registry to see if no errors are returned | ||
req, err := http.NewRequest("POST", "http://elastic:changeme@localhost:5601/api/ingest_manager/setup", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
req.Header.Add("kbn-xsrf", "ingest_manager") | ||
resp, err := http.DefaultClient.Do(req) | ||
defer resp.Body.Close() | ||
|
||
assert.Equal(t, 200, resp.StatusCode) | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Leaving this in as it could become useful for debugging purpose | ||
log.Println(string(body)) | ||
} |
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