harbor/tests/apitests/api-testing/lib/system.go
Daniel Jiang dcf4e2ee78 Update import path in go code
vmware -> goharbor

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
2018-08-23 17:50:53 +08:00

51 lines
1.1 KiB
Go

package lib
import (
"encoding/json"
"fmt"
"strings"
"github.com/goharbor/harbor/tests/apitests/api-testing/client"
"github.com/goharbor/harbor/tests/apitests/api-testing/models"
)
//SystemUtil : For getting system info
type SystemUtil struct {
rootURI string
hostname string
testingClient *client.APIClient
}
//NewSystemUtil : Constructor
func NewSystemUtil(rootURI, hostname string, httpClient *client.APIClient) *SystemUtil {
if len(strings.TrimSpace(rootURI)) == 0 || httpClient == nil {
return nil
}
return &SystemUtil{
rootURI: rootURI,
hostname: hostname,
testingClient: httpClient,
}
}
//GetSystemInfo : Get systeminfo
func (nsu *SystemUtil) GetSystemInfo() error {
url := nsu.rootURI + "/api/systeminfo"
data, err := nsu.testingClient.Get(url)
if err != nil {
return err
}
var info models.SystemInfo
if err := json.Unmarshal(data, &info); err != nil {
return err
}
if info.RegistryURL != nsu.hostname {
return fmt.Errorf("Invalid registry url in system info: expect %s got %s ", nsu.hostname, info.RegistryURL)
}
return nil
}