Improve error reporting for short cluster names (#377)
* Improve error reporting for short cluster names * Revert to clusterName
This commit is contained in:
parent
75a1d782b0
commit
1e53e22773
|
|
@ -2,10 +2,11 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -47,7 +48,7 @@ func parseWeekday(s string) (time.Weekday, error) {
|
||||||
func extractClusterName(clusterName string, teamName string) (string, error) {
|
func extractClusterName(clusterName string, teamName string) (string, error) {
|
||||||
teamNameLen := len(teamName)
|
teamNameLen := len(teamName)
|
||||||
if len(clusterName) < teamNameLen+2 {
|
if len(clusterName) < teamNameLen+2 {
|
||||||
return "", fmt.Errorf("name is too short")
|
return "", fmt.Errorf("cluster name must match {TEAM}-{NAME} format. Got cluster name '%v', team name '%v'", clusterName, teamName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if teamNameLen == 0 {
|
if teamNameLen == 0 {
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var parseTimeTests = []struct {
|
var parseTimeTests = []struct {
|
||||||
|
|
@ -49,8 +50,11 @@ var clusterNames = []struct {
|
||||||
{"acid-test", "test", "", errors.New("name must match {TEAM}-{NAME} format")},
|
{"acid-test", "test", "", errors.New("name must match {TEAM}-{NAME} format")},
|
||||||
{"-test", "", "", errors.New("team name is empty")},
|
{"-test", "", "", errors.New("team name is empty")},
|
||||||
{"-test", "-", "", errors.New("name must match {TEAM}-{NAME} format")},
|
{"-test", "-", "", errors.New("name must match {TEAM}-{NAME} format")},
|
||||||
{"", "-", "", errors.New("name is too short")},
|
{"", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '', team name '-'")},
|
||||||
{"-", "-", "", errors.New("name is too short")},
|
{"-", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '-', team name '-'")},
|
||||||
|
// user may specify the team part of the full cluster name differently from the team name returned by the Teams API
|
||||||
|
// in the case the actual Teams API name is long enough, this will fail the check
|
||||||
|
{"foo-bar", "qwerty", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name 'foo-bar', team name 'qwerty'")},
|
||||||
}
|
}
|
||||||
|
|
||||||
var cloneClusterDescriptions = []struct {
|
var cloneClusterDescriptions = []struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue