Пример #1
0
func (s *ErrorsSuite) TestErrorIsType(c *gc.C) {
	rootCause := errors.NewBadRequestf(nil, "some value", "")
	// Construct a new error, based on a bad request root cause.
	err := errors.Newf(rootCause, "an error occurred")
	// Check that the error is not falsely identified as something it is not.
	c.Assert(errors.IsNotAuthorized(err), gc.Equals, false)
	// Check that the error is correctly identified as a not found error.
	c.Assert(errors.IsBadRequest(err), gc.Equals, true)
}
Пример #2
0
func (s *JoyentStorage) Remove(name string) error {
	err := s.manta.DeleteObject(s.containerName, name)
	if err != nil {
		if je.IsResourceNotFound(err) {
			// gojoyent returns an error if file doesn't exist
			// just log a warning
			logger.Warningf("cannot delete %s from %s, already deleted", name, s.containerName)
		} else {
			return err
		}
	}

	if strings.Contains(name, "/") {
		var parents []string
		dirs := strings.Split(name, "/")
		for i := (len(dirs) - 1); i >= 0; i-- {
			if i < (len(dirs) - 1) {
				parents = append(parents, strings.Join(dirs[:(i+1)], "/"))
			}
		}

		for _, dir := range parents {
			err := s.manta.DeleteDirectory(path.Join(s.containerName, dir))
			if err != nil {
				if je.IsBadRequest(err) {
					// check if delete request returned a bad request error, i.e. directory is not empty
					// just log a warning
					logger.Warningf("cannot delete %s, not empty", dir)
				} else if je.IsResourceNotFound(err) {
					// check if delete request returned a resource not found error, i.e. directory was already deleted
					// just log a warning
					logger.Warningf("cannot delete %s, already deleted", dir)
				} else {
					return fmt.Errorf("cannot delete parent directory %q in control container %q: %v", dir, s.containerName, err)
				}
			}
		}
	}

	return nil
}
Пример #3
0
func (s *ErrorsSuite) TestCreateBadRequestError(c *gc.C) {
	context := "context"
	err := errors.NewBadRequestf(nil, context, "It was bad request: %s", context)
	c.Assert(errors.IsBadRequest(err), gc.Equals, true)
	c.Assert(err.Error(), gc.Equals, "It was bad request: context")
}