Question: I'm writing an appengine app in Go that uses [Google cloud storage](https://godoc.org/cloud.google.com/go/storage).

For example, my "reading" code looks like:

```
client, err := storage.NewClient(ctx)
if err != nil {
    return nil, err
}
defer func() {
    if err := client.Close(); err != nil {
        panic(err)
    }
}()
r, err := client.Bucket(BucketName).Object(id).NewReader(ctx)
if err != nil {
    return nil, err
}
defer r.Close()
return ioutil.ReadAll(r)

```

... where `ctx` is a context from appengine.

When I run this code in a unit test (using `aetest`), it actually sends requests to my cloud storage; I'd like to run this hermetically instead, similar to how `aetest` allows fake datastore calls.

(Possibly related [question](https://stackoverflow.com/questions/32613897/unit-testing-googles-cloud-storage-api), but it deals with python, and the linked [github issue](https://github.com/GoogleCloudPlatform/appengine-gcs-client/issues/21) indicates it's solved in a python-specific way).

How can I do this?

Answer: 
I have done something like this...

Since storage client is sending HTTPS request so I mocked the HTTPS server using `httptest`

```
func Test_StorageClient(t *testing.T) {
    tests := []struct {
        name        string
        mockHandler func() http.Handler
        wantErr     bool
    }{
        {
            name: "test1",
            mockHandler: func() http.Handler {
                return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                    w.Write([]byte("22\n96\n120\n"))
                    return
                })
            },
            wantErr: false,
        },
        {
            name: "test2 ",
            mockHandler: func() http.Handler {
                return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                    w.WriteHeader(http.StatusNotFound)
                    return
                })
            },
            wantErr: true,
        },
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            serv := httptest.NewTLSServer(tt.mockHandler())
            httpclient := http.Client{
                Transport: &http.Transport{
                    TLSClientConfig: &tls.Config{
                        InsecureSkipVerify: true,
                    },
                },
            }
            client, _ := storage.NewClient(context.Background(), option.WithEndpoint(serv.URL), option.WithoutAuthentication(), option.WithHTTPClient(&httpclient))
            got, err := readFileFromGCS(client)
            if (err != nil) != tt.wantErr {
                t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
                return
            }
        })
    }
}

```
Cloud Storage on the Python Development server is emulated using local files with the Blobstore service, which is why the solution of using a Blobstore stub with testbed (also Python-specific) worked. However there is no such local emulation for Cloud Storage on the Go runtime.

As Sachin suggested, the way to unit test Cloud Storage is to use a mock. This is the way it's done internally and on other runtimes, such as [node](https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1032).