ARO-RP/test/validate/error.go

39 строки
847 B
Go
Исходник Обычный вид История

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
)
2020-11-14 03:09:15 +03:00
func CloudError(t *testing.T, err error) {
2019-12-16 22:30:58 +03:00
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 '.'")
}
if strings.Contains(cloudErr.Target, `"`) {
t.Error(`target must not contain '"'`)
}
2019-12-16 22:30:58 +03:00
}