mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 20:26:13 +01:00
commit
e1f3ebc389
@ -29,9 +29,9 @@ env:
|
||||
HARBOR_ADMIN_PASSWD: Harbor12345
|
||||
|
||||
before_install:
|
||||
- ./tests/hostcfg.sh
|
||||
- sudo ./tests/hostcfg.sh
|
||||
- cd Deploy
|
||||
- ./prepare
|
||||
- sudo ./prepare
|
||||
- cd ..
|
||||
|
||||
install:
|
||||
@ -58,6 +58,8 @@ install:
|
||||
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||
- chmod +x docker-compose
|
||||
- sudo mv docker-compose /usr/local/bin
|
||||
- sudo sed -i '$a DOCKER_OPTS=\"$DOCKER_OPTS --insecure-registry 127.0.0.1\"' /etc/default/docker
|
||||
- sudo service docker restart
|
||||
- go get github.com/dghubble/sling
|
||||
- go get github.com/stretchr/testify
|
||||
|
||||
@ -78,4 +80,5 @@ script:
|
||||
|
||||
|
||||
# test for API
|
||||
- sudo ./tests/testprepare.sh
|
||||
- go test -v ./tests/apitests
|
||||
|
130
tests/apitests/hbapidelrpo_test.go
Normal file
130
tests/apitests/hbapidelrpo_test.go
Normal file
@ -0,0 +1,130 @@
|
||||
package HarborAPItest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/vmware/harbor/tests/apitests/apilib"
|
||||
)
|
||||
|
||||
func TestRepositoryDelete(t *testing.T) {
|
||||
fmt.Println("Test for Project Delete (ProjectDelete) API\n")
|
||||
assert := assert.New(t)
|
||||
|
||||
//prepare for test
|
||||
adminEr := &HarborAPI.UsrInfo{"admin", "Harbor1234"}
|
||||
admin := &HarborAPI.UsrInfo{"admin", "Harbor12345"}
|
||||
prjUsr := &HarborAPI.UsrInfo{"unknown", "unknown"}
|
||||
|
||||
fmt.Println("Checking repository status...\n")
|
||||
apiTest := HarborAPI.NewHarborAPI()
|
||||
var searchResault HarborAPI.Search
|
||||
searchResault, err := apiTest.SearchGet("library")
|
||||
//fmt.Printf("%+v\n", resault)
|
||||
|
||||
if err != nil {
|
||||
t.Error("Error while search project or repository", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
//assert.Equal(searchResault.Repositories[0].RepoName, "library/docker", "1st repo name should be")
|
||||
if !assert.Equal(searchResault.Repositories[0].RepoName, "library/docker", "1st repo name should be") {
|
||||
t.Error("fail to find repo 'library/docker'", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
fmt.Println("repo 'library/docker' exit\n")
|
||||
}
|
||||
//assert.Equal(searchResault.Repositories[1].RepoName, "library/hello-world", "2nd repo name should be")
|
||||
if !assert.Equal(searchResault.Repositories[1].RepoName, "library/hello-world", "2nd repo name should be") {
|
||||
t.Error("fail to find repo 'library/hello-world'", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
fmt.Println("repo 'library/hello-world' exit\n")
|
||||
}
|
||||
|
||||
//t.Log(resault)
|
||||
}
|
||||
|
||||
//case 1: admin login fail, expect repo delete fail.
|
||||
fmt.Println("case 1: admin login fail, expect repo delete fail.")
|
||||
|
||||
resault, err := apiTest.HarborLogin(*adminEr)
|
||||
if err != nil {
|
||||
t.Error("Error while admin login", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(resault, int(401), "Admin login status should be 401")
|
||||
//t.Log(resault)
|
||||
}
|
||||
if resault != 401 {
|
||||
t.Log(resault)
|
||||
} else {
|
||||
prjUsr = adminEr
|
||||
}
|
||||
|
||||
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/docker", "")
|
||||
if err != nil {
|
||||
t.Error("Error while delete repository", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(resault, int(401), "Case 1: Repository delete status should be 401")
|
||||
//t.Log(resault)
|
||||
}
|
||||
|
||||
//case 2: admin successful login, expect repository delete success.
|
||||
fmt.Println("case 2: admin successful login, expect repository delete success.")
|
||||
resault, err = apiTest.HarborLogin(*admin)
|
||||
if err != nil {
|
||||
t.Error("Error while admin login", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(resault, int(200), "Admin login status should be 200")
|
||||
//t.Log(resault)
|
||||
}
|
||||
if resault != 200 {
|
||||
t.Log(resault)
|
||||
} else {
|
||||
prjUsr = admin
|
||||
}
|
||||
|
||||
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/docker", "")
|
||||
if err != nil {
|
||||
t.Error("Error while delete repository", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
if assert.Equal(resault, int(200), "Case 2: Repository delete status should be 200") {
|
||||
fmt.Println("Repository 'library/docker' delete success.")
|
||||
}
|
||||
//t.Log(resault)
|
||||
}
|
||||
|
||||
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/hello-world", "")
|
||||
if err != nil {
|
||||
t.Error("Error while delete repository", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
if assert.Equal(resault, int(200), "Case 2: Repository delete status should be 200") {
|
||||
fmt.Println("Repository 'hello-world' delete success.")
|
||||
}
|
||||
//t.Log(resault)
|
||||
}
|
||||
|
||||
//case 3: delete one repo not exit, expect repo delete fail.
|
||||
fmt.Println("case 3: delete one repo not exit, expect repo delete fail.")
|
||||
|
||||
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/hello-world", "")
|
||||
if err != nil {
|
||||
t.Error("Error while delete repository", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
if assert.Equal(resault, int(404), "Case 3: Repository delete status should be 404") {
|
||||
fmt.Println("Repository 'hello-world' not exit.")
|
||||
}
|
||||
//t.Log(resault)
|
||||
}
|
||||
|
||||
//if resault.Response.StatusCode != 200 {
|
||||
// t.Log(resault.Response)
|
||||
//}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
|
||||
#echo $IP
|
||||
sed "s/reg.mydomain.com/$IP/" -i Deploy/harbor.cfg
|
||||
sudo sed "s/reg.mydomain.org/$IP/" -i Deploy/harbor.cfg
|
||||
|
@ -1,11 +1,10 @@
|
||||
IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
|
||||
#echo $IP
|
||||
docker pull hello-world
|
||||
docker pull docker
|
||||
#docker login -u admin -p Harbor12345 $IP
|
||||
docker login -u admin -p Harbor12345 127.0.0.1
|
||||
|
||||
docker tag hello-world $IP/library/hello-world
|
||||
docker push $IP/library/hello-world
|
||||
docker tag hello-world 127.0.0.1/library/hello-world
|
||||
docker push 127.0.0.1/library/hello-world
|
||||
|
||||
docker tag docker 127.0.0.1/library/docker
|
||||
docker push 127.0.0.1/library/docker
|
||||
|
||||
docker tag docker $IP/library/docker
|
||||
docker push $IP/library/docker
|
||||
|
Loading…
Reference in New Issue
Block a user