diff --git a/.travis.yml b/.travis.yml index b0dd4c556..80a1df4a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/tests/startuptest.go b/tests/startuptest.go deleted file mode 100644 index 5330b45b5..000000000 --- a/tests/startuptest.go +++ /dev/null @@ -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) - } - - } -} diff --git a/tests/startuptest.sh b/tests/startuptest.sh new file mode 100755 index 000000000..7a41cd768 --- /dev/null +++ b/tests/startuptest.sh @@ -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 + +