mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-16 20:01:35 +01:00
fix ut error in systeminfo_test.go
Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
parent
c9a8de9002
commit
36e1c13a43
@ -125,7 +125,7 @@ func (c *CfgManager) GetAll() map[string]interface{} {
|
||||
metaDataList := metadata.Instance().GetAll()
|
||||
for _, item := range metaDataList {
|
||||
cfgValue, err := c.store.GetAnyType(item.Name)
|
||||
if err != nil {
|
||||
if err != metadata.ErrValueNotSet && err != nil {
|
||||
log.Errorf("Failed to get value of key %v, error %v", item.Name, err)
|
||||
continue
|
||||
}
|
||||
@ -145,7 +145,7 @@ func (c *CfgManager) GetUserCfgs() map[string]interface{} {
|
||||
for _, item := range metaDataList {
|
||||
if item.Scope == metadata.UserScope {
|
||||
cfgValue, err := c.store.GetAnyType(item.Name)
|
||||
if err != nil {
|
||||
if err != metadata.ErrValueNotSet && err != nil {
|
||||
log.Errorf("Failed to get value of key %v, error %v", item.Name, err)
|
||||
continue
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ var (
|
||||
{Name: "uaa_verify_cert", Scope: UserScope, Group: UAAGroup, EnvKey: "UAA_VERIFY_CERT", DefaultValue: "false", ItemType: &BoolType{}, Editable: false},
|
||||
|
||||
{Name: "with_chartmuseum", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_CHARTMUSEUM", DefaultValue: "false", ItemType: &BoolType{}, Editable: true},
|
||||
{Name: "with_clair", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_CLAIR", DefaultValue: "true", ItemType: &BoolType{}, Editable: true},
|
||||
{Name: "with_clair", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_CLAIR", DefaultValue: "false", ItemType: &BoolType{}, Editable: true},
|
||||
{Name: "with_notary", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_NOTARY", DefaultValue: "false", ItemType: &BoolType{}, Editable: true},
|
||||
}
|
||||
)
|
||||
|
@ -71,6 +71,9 @@ type GCRep struct {
|
||||
|
||||
// Valid validates the gc request
|
||||
func (gr *GCReq) Valid(v *validation.Validation) {
|
||||
if gr.Schedule == nil {
|
||||
return
|
||||
}
|
||||
switch gr.Schedule.Type {
|
||||
case ScheduleDaily, ScheduleWeekly:
|
||||
if gr.Schedule.Offtime < 0 || gr.Schedule.Offtime > 3600*24 {
|
||||
|
@ -16,13 +16,13 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/common"
|
||||
"github.com/goharbor/harbor/src/core/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TODO
|
||||
/*func TestGetVolumeInfo(t *testing.T) {
|
||||
func TestGetVolumeInfo(t *testing.T) {
|
||||
fmt.Println("Testing Get Volume Info")
|
||||
assert := assert.New(t)
|
||||
apiTest := newHarborAPI()
|
||||
@ -51,9 +51,12 @@ import (
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestGetGeneralInfo(t *testing.T) {
|
||||
config.Upload(map[string]interface{}{
|
||||
common.ReadOnly: false,
|
||||
})
|
||||
apiTest := newHarborAPI()
|
||||
code, body, err := apiTest.GetGeneralInfo()
|
||||
assert := assert.New(t)
|
||||
@ -61,41 +64,39 @@ func TestGetGeneralInfo(t *testing.T) {
|
||||
assert.Equal(200, code, fmt.Sprintf("Unexpected status code: %d", code))
|
||||
g := &GeneralInfo{}
|
||||
err = json.Unmarshal(body, g)
|
||||
// TODO
|
||||
// assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err))
|
||||
assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err))
|
||||
assert.Equal(false, g.WithNotary, "with notary should be false")
|
||||
// assert.Equal(true, g.HasCARoot, "has ca root should be true")
|
||||
// assert.NotEmpty(g.HarborVersion, "harbor version should not be empty")
|
||||
assert.Equal(true, g.HasCARoot, "has ca root should be true")
|
||||
assert.NotEmpty(g.HarborVersion, "harbor version should not be empty")
|
||||
assert.Equal(false, g.ReadOnly, "readonly should be false")
|
||||
}
|
||||
|
||||
// TODO
|
||||
// func TestGetCert(t *testing.T) {
|
||||
// fmt.Println("Testing Get Cert")
|
||||
// assert := assert.New(t)
|
||||
// apiTest := newHarborAPI()
|
||||
//
|
||||
// // case 1: get cert without admin role
|
||||
// code, content, err := apiTest.CertGet(*testUser)
|
||||
// if err != nil {
|
||||
// t.Error("Error occurred while get system cert")
|
||||
// t.Log(err)
|
||||
// } else {
|
||||
// assert.Equal(200, code, "Get system cert should be 200")
|
||||
// assert.Equal("test for ca.crt.\n", string(content), "Get system cert content should be equal")
|
||||
// }
|
||||
// // case 2: get cert with admin role
|
||||
// code, content, err = apiTest.CertGet(*admin)
|
||||
// if err != nil {
|
||||
// t.Error("Error occurred while get system cert")
|
||||
// t.Log(err)
|
||||
// } else {
|
||||
// assert.Equal(200, code, "Get system cert should be 200")
|
||||
// assert.Equal("test for ca.crt.\n", string(content), "Get system cert content should be equal")
|
||||
//
|
||||
// }
|
||||
// CommonDelUser()
|
||||
// }
|
||||
func TestGetCert(t *testing.T) {
|
||||
fmt.Println("Testing Get Cert")
|
||||
assert := assert.New(t)
|
||||
apiTest := newHarborAPI()
|
||||
|
||||
// case 1: get cert without admin role
|
||||
code, content, err := apiTest.CertGet(*testUser)
|
||||
if err != nil {
|
||||
t.Error("Error occurred while get system cert")
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(200, code, "Get system cert should be 200")
|
||||
assert.Equal("test for ca.crt.\n", string(content), "Get system cert content should be equal")
|
||||
}
|
||||
// case 2: get cert with admin role
|
||||
code, content, err = apiTest.CertGet(*admin)
|
||||
if err != nil {
|
||||
t.Error("Error occurred while get system cert")
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(200, code, "Get system cert should be 200")
|
||||
assert.Equal("test for ca.crt.\n", string(content), "Get system cert content should be equal")
|
||||
|
||||
}
|
||||
CommonDelUser()
|
||||
}
|
||||
func TestPing(t *testing.T) {
|
||||
apiTest := newHarborAPI()
|
||||
code, _, err := apiTest.Ping()
|
||||
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import argparse
|
||||
import requests
|
||||
import json
|
||||
import requests
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -29,7 +29,7 @@ for item in args.config :
|
||||
url = "https://"+args.host+"/api/configurations"
|
||||
user = args.user
|
||||
passwd = args.password
|
||||
|
||||
|
||||
# Make a request to the endpoint using the correct auth values
|
||||
auth_values = (user, passwd)
|
||||
session = requests.Session()
|
||||
|
Loading…
Reference in New Issue
Block a user