replace startuptest

This commit is contained in:
wy65701436 2017-03-23 19:12:04 -07:00
parent 74e7b66aa0
commit 5f33b3f933
3 changed files with 29 additions and 50 deletions

View File

@ -101,7 +101,7 @@ script:
- docker ps
- ./tests/notarytest.sh
- go run tests/startuptest.go https://localhost/
- ./tests/startuptest.sh
- go run tests/userlogintest.go -name ${HARBOR_ADMIN} -passwd ${HARBOR_ADMIN_PASSWD}
# - sudo ./tests/testprepare.sh

View File

@ -1,49 +0,0 @@
// Fetch prints the content found at a URL.
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
)
func main() {
time.Sleep(60 * time.Second)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
var client = &http.Client{
Timeout: time.Second * 30,
Transport: tr,
}
for _, url := range os.Args[1:] {
resp, err := client.Get(url)
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: %v\n", err)
os.Exit(1)
}
b, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: reading %s: %v\n", url, err)
os.Exit(1)
}
// fmt.Printf("%s", b)
if strings.Contains(string(b), "Harbor") {
fmt.Printf("sucess!\n")
} else {
fmt.Println("the response does not contain \"Harbor\"!")
fmt.Println(string(b))
os.Exit(1)
}
}
}

28
tests/startuptest.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
set +e
TIMEOUT=12
while [ $TIMEOUT -gt 0 ]; do
STATUS=$(curl --insecure -s -o /dev/null -w '%{http_code}' https://localhost/)
if [ $STATUS -eq 200 ]; then
break
fi
TIMEOUT=$(($TIMEOUT - 1))
sleep 5
done
if [ $TIMEOUT -eq 0 ]; then
echo "Harbor cannot reach within one minute."
exit 1
fi
curl --insecure -s -L -H "Accept: application/json" https://localhost/ | grep "Harbor" > /dev/null
if [ $? -eq 0 ]; then
echo "Harbor is running success."
else
echo "Harbor is running fail."
exit 1
fi