本文整理汇总了Golang中github.com/openshift/origin/pkg/deploy/api/test.OkSelector函数的典型用法代码示例。如果您正苦于以下问题:Golang OkSelector函数的具体用法?Golang OkSelector怎么用?Golang OkSelector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OkSelector函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidateSelectorMatchesPodTemplateLabels
func TestValidateSelectorMatchesPodTemplateLabels(t *testing.T) {
tests := map[string]struct {
spec api.DeploymentConfigSpec
expectedErr bool
errorType field.ErrorType
field string
}{
"valid template labels": {
spec: api.DeploymentConfigSpec{
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
},
"invalid template labels": {
spec: api.DeploymentConfigSpec{
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
expectedErr: true,
errorType: field.ErrorTypeInvalid,
field: "spec.template.metadata.labels",
},
}
for name, test := range tests {
if test.expectedErr {
test.spec.Template.Labels["a"] = "c"
}
errs := ValidateDeploymentConfigSpec(test.spec)
if len(errs) == 0 && test.expectedErr {
t.Errorf("%s: expected failure", name)
continue
}
if !test.expectedErr {
continue
}
if len(errs) != 1 {
t.Errorf("%s: expected one error, got %d", name, len(errs))
continue
}
err := errs[0]
if err.Type != test.errorType {
t.Errorf("%s: expected error to have type %q, got %q", name, test.errorType, err.Type)
}
if err.Field != test.field {
t.Errorf("%s: expected error to have field %q, got %q", name, test.field, err.Field)
}
}
}
示例2: TestValidateDeploymentConfigDefaultImageStreamKind
func TestValidateDeploymentConfigDefaultImageStreamKind(t *testing.T) {
config := &api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: []api.DeploymentTriggerPolicy{
{
Type: api.DeploymentTriggerOnImageChange,
ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
From: kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "name:v1",
},
ContainerNames: []string{"foo"},
},
},
},
Selector: test.OkSelector(),
Template: test.OkPodTemplate(),
Strategy: test.OkStrategy(),
},
}
if errs := ValidateDeploymentConfig(config); len(errs) > 0 {
t.Errorf("Unxpected non-empty error list: %v", errs)
}
}
示例3: TestValidateDeploymentConfigOK
func TestValidateDeploymentConfigOK(t *testing.T) {
errs := ValidateDeploymentConfig(&api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: manualTrigger(),
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
})
if len(errs) > 0 {
t.Errorf("Unxpected non-empty error list: %#v", errs)
}
}
示例4: rollingConfig
func rollingConfig(interval, updatePeriod, timeout int) api.DeploymentConfig {
return api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Triggers: manualTrigger(),
Strategy: api.DeploymentStrategy{
Type: api.DeploymentStrategyTypeRolling,
RollingParams: &api.RollingDeploymentStrategyParams{
IntervalSeconds: mkint64p(interval),
UpdatePeriodSeconds: mkint64p(updatePeriod),
TimeoutSeconds: mkint64p(timeout),
MaxSurge: intstr.FromInt(1),
},
},
Template: test.OkPodTemplate(),
Selector: test.OkSelector(),
},
}
}
示例5: rollingConfigMax
func rollingConfigMax(maxSurge, maxUnavailable intstr.IntOrString) api.DeploymentConfig {
return api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Triggers: manualTrigger(),
Strategy: api.DeploymentStrategy{
Type: api.DeploymentStrategyTypeRolling,
RollingParams: &api.RollingDeploymentStrategyParams{
IntervalSeconds: mkint64p(1),
UpdatePeriodSeconds: mkint64p(1),
TimeoutSeconds: mkint64p(1),
MaxSurge: maxSurge,
MaxUnavailable: maxUnavailable,
},
},
Template: test.OkPodTemplate(),
Selector: test.OkSelector(),
},
}
}
示例6: TestValidateDeploymentConfigICTMissingImage
func TestValidateDeploymentConfigICTMissingImage(t *testing.T) {
dc := &api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: []api.DeploymentTriggerPolicy{test.OkImageChangeTrigger()},
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplateMissingImage("container1"),
},
}
errs := ValidateDeploymentConfig(dc)
if len(errs) > 0 {
t.Errorf("Unexpected non-empty error list: %+v", errs)
}
for _, c := range dc.Spec.Template.Spec.Containers {
if c.Image == "unset" {
t.Errorf("%s image field still has validation fake out value of %s", c.Name, c.Image)
}
}
}
示例7: TestValidateDeploymentConfigMissingFields
func TestValidateDeploymentConfigMissingFields(t *testing.T) {
errorCases := map[string]struct {
DeploymentConfig api.DeploymentConfig
ErrorType field.ErrorType
Field string
}{
"missing name": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "", Namespace: "bar"},
Spec: test.OkDeploymentConfigSpec(),
},
field.ErrorTypeRequired,
"metadata.name",
},
"missing namespace": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: ""},
Spec: test.OkDeploymentConfigSpec(),
},
field.ErrorTypeRequired,
"metadata.namespace",
},
"invalid name": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "-foo", Namespace: "bar"},
Spec: test.OkDeploymentConfigSpec(),
},
field.ErrorTypeInvalid,
"metadata.name",
},
"invalid namespace": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "-bar"},
Spec: test.OkDeploymentConfigSpec(),
},
field.ErrorTypeInvalid,
"metadata.namespace",
},
"missing trigger.type": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: []api.DeploymentTriggerPolicy{
{
ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
ContainerNames: []string{"foo"},
},
},
},
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
},
field.ErrorTypeRequired,
"spec.triggers[0].type",
},
"missing Trigger imageChangeParams.from": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: []api.DeploymentTriggerPolicy{
{
Type: api.DeploymentTriggerOnImageChange,
ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
ContainerNames: []string{"foo"},
},
},
},
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
},
field.ErrorTypeRequired,
"spec.triggers[0].imageChangeParams.from",
},
"invalid Trigger imageChangeParams.from.kind": {
api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: []api.DeploymentTriggerPolicy{
{
Type: api.DeploymentTriggerOnImageChange,
ImageChangeParams: &api.DeploymentTriggerImageChangeParams{
From: kapi.ObjectReference{
Kind: "Invalid",
Name: "name:tag",
},
ContainerNames: []string{"foo"},
},
},
},
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
//.........这里部分代码省略.........
示例8: TestValidateDeploymentConfigUpdate
func TestValidateDeploymentConfigUpdate(t *testing.T) {
oldConfig := &api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar", ResourceVersion: "1"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: manualTrigger(),
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
Status: api.DeploymentConfigStatus{
LatestVersion: 5,
},
}
newConfig := &api.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "bar", ResourceVersion: "1"},
Spec: api.DeploymentConfigSpec{
Replicas: 1,
Triggers: manualTrigger(),
Selector: test.OkSelector(),
Strategy: test.OkStrategy(),
Template: test.OkPodTemplate(),
},
Status: api.DeploymentConfigStatus{
LatestVersion: 3,
},
}
scenarios := []struct {
oldLatestVersion int
newLatestVersion int
}{
{5, 3},
{5, 7},
{0, -1},
}
for _, values := range scenarios {
oldConfig.Status.LatestVersion = values.oldLatestVersion
newConfig.Status.LatestVersion = values.newLatestVersion
errs := ValidateDeploymentConfigUpdate(newConfig, oldConfig)
if len(errs) == 0 {
t.Errorf("Expected update failure")
}
for i := range errs {
if errs[i].Type != field.ErrorTypeInvalid {
t.Errorf("expected update error to have type %s: %v", field.ErrorTypeInvalid, errs[i])
}
if errs[i].Field != "status.latestVersion" {
t.Errorf("expected update error to have field %s: %v", "latestVersion", errs[i])
}
}
}
// testing for a successful update
oldConfig.Status.LatestVersion = 5
newConfig.Status.LatestVersion = 6
errs := ValidateDeploymentConfigUpdate(newConfig, oldConfig)
if len(errs) > 0 {
t.Errorf("Unexpected update failure")
}
}