本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/errors.NewModelAlreadyExistsError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewModelAlreadyExistsError函數的具體用法?Golang NewModelAlreadyExistsError怎麽用?Golang NewModelAlreadyExistsError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewModelAlreadyExistsError函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateServiceKey
func (c CloudControllerServiceKeyRepository) CreateServiceKey(instanceGUID string, keyName string, params map[string]interface{}) error {
path := "/v2/service_keys"
request := models.ServiceKeyRequest{
Name: keyName,
ServiceInstanceGUID: instanceGUID,
Params: params,
}
jsonBytes, err := json.Marshal(request)
if err != nil {
return err
}
err = c.gateway.CreateResource(c.config.APIEndpoint(), path, bytes.NewReader(jsonBytes))
if httpErr, ok := err.(errors.HTTPError); ok {
switch httpErr.ErrorCode() {
case errors.ServiceKeyNameTaken:
return errors.NewModelAlreadyExistsError("Service key", keyName)
case errors.UnbindableService:
return errors.NewUnbindableServiceError()
default:
return errors.New(httpErr.Error())
}
}
return nil
}
示例2: CreateServiceInstance
func (repo CloudControllerServiceRepository) CreateServiceInstance(name, planGUID string, params map[string]interface{}, tags []string) (err error) {
path := "/v2/service_instances?accepts_incomplete=true"
request := models.ServiceInstanceCreateRequest{
Name: name,
PlanGUID: planGUID,
SpaceGUID: repo.config.SpaceFields().GUID,
Params: params,
Tags: tags,
}
jsonBytes, err := json.Marshal(request)
if err != nil {
return err
}
err = repo.gateway.CreateResource(repo.config.APIEndpoint(), path, bytes.NewReader(jsonBytes))
if httpErr, ok := err.(errors.HTTPError); ok && httpErr.ErrorCode() == errors.ServiceInstanceNameTaken {
serviceInstance, findInstanceErr := repo.FindInstanceByName(name)
if findInstanceErr == nil && serviceInstance.ServicePlan.GUID == planGUID {
return errors.NewModelAlreadyExistsError("Service", name)
}
}
return
}
示例3: CreateServiceKey
func (c CloudControllerServiceKeyRepository) CreateServiceKey(instanceGuid string, keyName string, params map[string]interface{}) error {
path := "/v2/service_keys"
request := models.ServiceKeyRequest{
Name: keyName,
ServiceInstanceGuid: instanceGuid,
Params: params,
}
jsonBytes, err := json.Marshal(request)
if err != nil {
return err
}
err = c.gateway.CreateResource(c.config.ApiEndpoint(), path, bytes.NewReader(jsonBytes))
if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.SERVICE_KEY_NAME_TAKEN {
return errors.NewModelAlreadyExistsError("Service key", keyName)
} else if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.UNBINDABLE_SERVICE {
return errors.NewUnbindableServiceError()
} else if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() != "" {
return errors.New(httpErr.Error())
}
return nil
}
示例4: Create
func (repo *FakeUserRepository) Create(username, password string) (apiErr error) {
repo.CreateUserUsername = username
repo.CreateUserPassword = password
if repo.CreateUserExists {
apiErr = errors.NewModelAlreadyExistsError("User", username)
}
return
}
示例5: Create
func (repo *FakeUserRepository) Create(username, password string) (apiErr error) {
repo.CreateUserUsername = username
repo.CreateUserPassword = password
if repo.CreateUserReturnsHttpError {
apiErr = errors.NewHttpError(403, "403", "Forbidden")
}
if repo.CreateUserExists {
apiErr = errors.NewModelAlreadyExistsError("User", username)
}
return
}
示例6: CreateServiceKey
func (c CloudControllerServiceKeyRepository) CreateServiceKey(instanceId string, keyName string) error {
path := "/v2/service_keys"
data := fmt.Sprintf(`{"service_instance_guid":"%s","name":"%s"}`, instanceId, keyName)
err := c.gateway.CreateResource(c.config.ApiEndpoint(), path, strings.NewReader(data))
if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.SERVICE_KEY_NAME_TAKEN {
return errors.NewModelAlreadyExistsError("Service key", keyName)
} else if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.UNBINDABLE_SERVICE {
return errors.NewUnbindableServiceError()
} else if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() != "" {
return errors.New(httpErr.Error())
}
return nil
}
示例7: CreateServiceInstance
func (repo CloudControllerServiceRepository) CreateServiceInstance(name, planGuid string) (err error) {
path := fmt.Sprintf("%s/v2/service_instances", repo.config.ApiEndpoint())
data := fmt.Sprintf(
`{"name":"%s","service_plan_guid":"%s","space_guid":"%s", "async": true}`,
name, planGuid, repo.config.SpaceFields().Guid,
)
err = repo.gateway.CreateResource(path, strings.NewReader(data))
if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.SERVICE_INSTANCE_NAME_TAKEN {
serviceInstance, findInstanceErr := repo.FindInstanceByName(name)
if findInstanceErr == nil && serviceInstance.ServicePlan.Guid == planGuid {
return errors.NewModelAlreadyExistsError("Service", name)
}
}
return
}
示例8: Create
func (repo CloudControllerUserRepository) Create(username, password string) (err error) {
uaaEndpoint, err := repo.getAuthEndpoint()
if err != nil {
return
}
path := "/Users"
body, err := json.Marshal(resources.NewUAAUserResource(username, password))
if err != nil {
return
}
createUserResponse := &resources.UAAUserFields{}
err = repo.uaaGateway.CreateResource(uaaEndpoint, path, bytes.NewReader(body), createUserResponse)
switch httpErr := err.(type) {
case nil:
case errors.HttpError:
if httpErr.StatusCode() == http.StatusConflict {
err = errors.NewModelAlreadyExistsError("user", username)
return
}
return
default:
return
}
path = "/v2/users"
body, err = json.Marshal(resources.Metadata{
Guid: createUserResponse.Id,
})
if err != nil {
return
}
return repo.ccGateway.CreateResource(repo.config.ApiEndpoint(), path, bytes.NewReader(body))
}
示例9:
})
Describe("requiremnts are satisfied", func() {
It("create service key successfully", func() {
callCreateService([]string{"fake-service-instance", "fake-service-key"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating service key", "fake-service-key", "for service instance", "fake-service-instance", "as", "my-user"},
[]string{"OK"},
))
Expect(serviceKeyRepo.CreateServiceKeyMethod.InstanceGuid).To(Equal("fake-instance-guid"))
Expect(serviceKeyRepo.CreateServiceKeyMethod.KeyName).To(Equal("fake-service-key"))
})
It("create service key failed when the service key already exists", func() {
serviceKeyRepo.CreateServiceKeyMethod.Error = errors.NewModelAlreadyExistsError("Service key", "exist-service-key")
callCreateService([]string{"fake-service-instance", "exist-service-key"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating service key", "exist-service-key", "for service instance", "fake-service-instance", "as", "my-user"},
[]string{"OK"},
[]string{"Service key exist-service-key already exists"}))
})
It("create service key failed when the service is unbindable", func() {
serviceKeyRepo.CreateServiceKeyMethod.Error = errors.NewUnbindableServiceError()
callCreateService([]string{"fake-service-instance", "exist-service-key"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating service key", "exist-service-key", "for service instance", "fake-service-instance", "as", "my-user"},
示例10:
})
})
It("successfully creates a service", func() {
callCreateService([]string{"cleardb", "spark", "my-cleardb-service"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating service", "my-cleardb-service", "my-org", "my-space", "my-user"},
[]string{"OK"},
))
Expect(serviceRepo.CreateServiceInstanceArgs.Name).To(Equal("my-cleardb-service"))
Expect(serviceRepo.CreateServiceInstanceArgs.PlanGuid).To(Equal("cleardb-spark-guid"))
})
It("warns the user when the service already exists with the same service plan", func() {
serviceRepo.CreateServiceInstanceReturns.Error = errors.NewModelAlreadyExistsError("Service", "my-cleardb-service")
callCreateService([]string{"cleardb", "spark", "my-cleardb-service"})
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating service", "my-cleardb-service"},
[]string{"OK"},
[]string{"my-cleardb-service", "already exists"},
))
Expect(serviceRepo.CreateServiceInstanceArgs.Name).To(Equal("my-cleardb-service"))
Expect(serviceRepo.CreateServiceInstanceArgs.PlanGuid).To(Equal("cleardb-spark-guid"))
})
Context("When there are multiple services with the same label", func() {
It("finds the plan even if it has to search multiple services", func() {
offering2.Label = "cleardb"
示例11:
runCommand("my-user", "my-password")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Creating user", "my-user"},
[]string{"OK"},
[]string{"TIP"},
))
userName, password := userRepo.CreateArgsForCall(0)
Expect(userName).To(Equal("my-user"))
Expect(password).To(Equal("my-password"))
})
Context("when creating the user returns an error", func() {
It("prints a warning when the given user already exists", func() {
userRepo.CreateReturns(errors.NewModelAlreadyExistsError("User", "my-user"))
runCommand("my-user", "my-password")
Expect(ui.WarnOutputs).To(ContainSubstrings(
[]string{"already exists"},
))
Expect(ui.Outputs()).ToNot(ContainSubstrings([]string{"FAILED"}))
})
It("fails when any error other than alreadyExists is returned", func() {
userRepo.CreateReturns(errors.NewHTTPError(403, "403", "Forbidden"))
runCommand("my-user", "my-password")