Documentation ¶
Overview ¶
Example (TopFunction) ¶
package main import ( "context" "fmt" "knative.dev/pkg/test/gcs" ) // Example on how to override errors const ( bkt = "NewBkt" proj = "NewProject" ) func topFunction(c gcs.Client) error { ctx := context.Background() if err := c.NewStorageBucket(ctx, bkt, proj); err != nil { return err } // Should have returned error, but SetError override to nil if _, err := c.ReadObject(ctx, bkt, "non-existent-file"); err != nil { return err } if _, err := c.ListChildrenFiles(ctx, bkt, ""); err != nil { return err } if _, err := c.ListChildrenFiles(ctx, bkt, ""); err != nil { return err } // Should not have returned error, but SetError override to NewNoBucketError(bkt) if _, err := c.ListChildrenFiles(ctx, bkt, ""); err != nil { return err } return nil } func main() { mockClient := newClientMocker() // Call to ReadObject, first call should return error, but returns nil // because it is overridden. mockClient.SetError( map[Method]*ReturnError{ MethodReadObject: { NumCall: uint8(0), Err: nil, }, MethodListChildrenFiles: { NumCall: uint8(2), Err: NewNoBucketError(bkt), }, }) fmt.Println(topFunction(mockClient)) }
Output: no bucket "NewBkt"
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // MethodNewStorageBucket mocks MethodNewStorageBucket. MethodNewStorageBucket = Method("NewStorageBucket") // MethodDeleteStorageBucket mocks NewDeleteStorageBucket. MethodDeleteStorageBucket = Method("NewDeleteStorageBucket") // MethodListChildrenFiles mocks ListChildrenFiles. MethodListChildrenFiles = Method("ListChildrenFiles") // MethodListDirectChildren mocks ListDirectChildren. MethodListDirectChildren = Method("ListDirectChildren") // MethodAttrObject mocks AttrObject. MethodAttrObject = Method("AttrObject") // MethodCopyObject mocks CopyObject. MethodCopyObject = Method("CopyObject") // MethodReadObject mocks ReadObject. MethodReadObject = Method("ReadObject") // MethodWriteObject mocks WriteObject. MethodWriteObject = Method("WriteObject") // MethodDeleteObject mocks DeleteObject. MethodDeleteObject = Method("DeleteObject") // MethodDownload mocks Download. MethodDownload = Method("Download") // MethodUpload mocks Upload. MethodUpload = Method("Upload") )
Functions ¶
func NewBucketExistError ¶
func NewNoBucketError ¶
func NewNoObjectError ¶
func NewNotEmptyBucketError ¶
Types ¶
type ReturnError ¶
ReturnError is a custom error for specific methods
Click to show internal directories.
Click to hide internal directories.