2019-12-16 22:30:58 +03:00
|
|
|
package validate
|
|
|
|
|
2019-12-17 04:16:50 +03:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
2019-12-16 22:30:58 +03:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"unicode"
|
|
|
|
|
2019-12-17 04:26:21 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/api"
|
2019-12-16 22:30:58 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func CloudError(t *testing.T, err error) *api.CloudError {
|
|
|
|
cloudErr, ok := err.(*api.CloudError)
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("must return *api.CloudError")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cloudErr.Code == "" {
|
|
|
|
t.Error("code is required")
|
|
|
|
}
|
|
|
|
if cloudErr.Message == "" {
|
|
|
|
t.Error("message is required")
|
|
|
|
}
|
|
|
|
if cloudErr.Message != "" && !unicode.IsUpper(rune(cloudErr.Message[0])) {
|
|
|
|
t.Error("message must start with upper case letter")
|
|
|
|
}
|
|
|
|
if strings.Contains(cloudErr.Message, `"`) {
|
|
|
|
t.Error(`message must not contain '"'`)
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(cloudErr.Message, ".") {
|
|
|
|
t.Error("message must end in '.'")
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloudErr
|
|
|
|
}
|