[#12] Implement RedfishConfigError interface

Implement RedfishConfigError
Rename RedfishConfigError to follow airship norms IE ErrRedfish...
Update unit tests

Change-Id: I49051315460b5d261186f32bae6101a752740eae
This commit is contained in:
Alexander Hughes 2020-02-11 11:54:18 -05:00
parent 1399c569f4
commit 7bfdea075e
3 changed files with 20 additions and 12 deletions

View File

@ -17,14 +17,12 @@ func NewRedfishClientErrorf(format string, v ...interface{}) error {
return e
}
type RedfishConfigError struct {
aerror.AirshipError
type ErrRedfishMissingConfig struct {
What string
}
func NewRedfishConfigErrorf(format string, v ...interface{}) error {
e := &RedfishConfigError{}
e.Message = fmt.Sprintf(format, v...)
return e
func (e ErrRedfishMissingConfig) Error() string {
return "missing configuration: " + e.What
}
// Redfish client return error if response has no body.

View File

@ -2,6 +2,7 @@ package redfish
import (
"context"
"fmt"
"net/url"
redfishApi "opendev.org/airship/go-redfish/api"
@ -84,17 +85,23 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
) (RedfishRemoteDirect, error) {
if remoteURL == "" {
return RedfishRemoteDirect{},
NewRedfishConfigErrorf("redfish remote url empty")
ErrRedfishMissingConfig{
What: "redfish remote url empty",
}
}
if ephNodeID == "" {
return RedfishRemoteDirect{},
NewRedfishConfigErrorf("redfish ephemeral node id empty")
ErrRedfishMissingConfig{
What: "redfish ephemeral node id empty",
}
}
if isoPath == "" {
return RedfishRemoteDirect{},
NewRedfishConfigErrorf("redfish ephemeral node iso Path empty")
ErrRedfishMissingConfig{
What: "redfish ephemeral node iso Path empty",
}
}
cfg := &redfishClient.Configuration{
@ -107,7 +114,10 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
parsedUrl, err := url.Parse(remoteURL)
if err != nil {
return RedfishRemoteDirect{}, NewRedfishConfigErrorf("Invalid URL format: %v", err)
return RedfishRemoteDirect{},
ErrRedfishMissingConfig{
What: fmt.Sprintf("invalid url format: %v", err),
}
}
client := RedfishRemoteDirect{

View File

@ -52,7 +52,7 @@ func TestRedfishRemoteDirectWithEmptyURL(t *testing.T) {
err := DoRemoteDirect(s)
_, ok := err.(*redfish.RedfishConfigError)
_, ok := err.(redfish.ErrRedfishMissingConfig)
assert.True(t, ok)
}
@ -68,6 +68,6 @@ func TestRedfishRemoteDirectWithEmptyIsoPath(t *testing.T) {
err := DoRemoteDirect(s)
_, ok := err.(*redfish.RedfishConfigError)
_, ok := err.(redfish.ErrRedfishMissingConfig)
assert.True(t, ok)
}