[#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:
parent
1399c569f4
commit
7bfdea075e
@ -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.
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user