本文整理汇总了Golang中github.com/openshift/origin/pkg/deploy/api.DeploymentConfig.Triggers方法的典型用法代码示例。如果您正苦于以下问题:Golang DeploymentConfig.Triggers方法的具体用法?Golang DeploymentConfig.Triggers怎么用?Golang DeploymentConfig.Triggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/origin/pkg/deploy/api.DeploymentConfig
的用法示例。
在下文中一共展示了DeploymentConfig.Triggers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHandle_updateOk
// TestHandle_updateOk ensures that an updated config (version >0) results in
// a new deployment with the appropriate replica count based on a variety of
// existing prior deployments.
func TestHandle_updateOk(t *testing.T) {
var (
config *deployapi.DeploymentConfig
deployed *kapi.ReplicationController
existingDeployments *kapi.ReplicationControllerList
)
controller := &DeploymentConfigController{
makeDeployment: func(config *deployapi.DeploymentConfig) (*kapi.ReplicationController, error) {
return deployutil.MakeDeployment(config, api.Codec)
},
deploymentClient: &deploymentClientImpl{
createDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
deployed = deployment
return deployment, nil
},
listDeploymentsForConfigFunc: func(namespace, configName string) (*kapi.ReplicationControllerList, error) {
return existingDeployments, nil
},
updateDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
t.Fatalf("unexpected update call with deployment %v", deployment)
return nil, nil
},
},
osClient: testclient.NewSimpleFake(),
}
type existing struct {
version int
replicas int
status deployapi.DeploymentStatus
}
type scenario struct {
version int
expectedReplicas int
existing []existing
}
scenarios := []scenario{
{1, 1, []existing{}},
{2, 1, []existing{
{1, 1, deployapi.DeploymentStatusComplete},
}},
{3, 4, []existing{
{1, 0, deployapi.DeploymentStatusComplete},
{2, 4, deployapi.DeploymentStatusComplete},
}},
{3, 4, []existing{
{1, 4, deployapi.DeploymentStatusComplete},
{2, 1, deployapi.DeploymentStatusFailed},
}},
{4, 2, []existing{
{1, 0, deployapi.DeploymentStatusComplete},
{2, 0, deployapi.DeploymentStatusFailed},
{3, 2, deployapi.DeploymentStatusComplete},
}},
// Scramble the order of the previous to ensure we still get it right.
{4, 2, []existing{
{2, 0, deployapi.DeploymentStatusFailed},
{3, 2, deployapi.DeploymentStatusComplete},
{1, 0, deployapi.DeploymentStatusComplete},
}},
}
for _, scenario := range scenarios {
deployed = nil
config = deploytest.OkDeploymentConfig(scenario.version)
config.Triggers = []deployapi.DeploymentTriggerPolicy{}
existingDeployments = &kapi.ReplicationControllerList{}
for _, e := range scenario.existing {
d, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(e.version), api.Codec)
d.Spec.Replicas = e.replicas
d.Annotations[deployapi.DeploymentStatusAnnotation] = string(e.status)
existingDeployments.Items = append(existingDeployments.Items, *d)
}
err := controller.Handle(config)
if deployed == nil {
t.Fatalf("expected a deployment")
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
desired, hasDesired := deployutil.DeploymentDesiredReplicas(deployed)
if !hasDesired {
t.Fatalf("expected desired replicas")
}
if e, a := scenario.expectedReplicas, desired; e != a {
t.Errorf("expected desired replicas %d, got %d", e, a)
}
}
}