func (cc *ConditionalClient) If(read, write *storage.Conditions) gcs.ConditionalClient {
	return &ConditionalClient{
		UploadClient: cc.UploadClient,
		read:         read,
		write:        write,
		Lock:         cc.Lock,
	}
}
If returns a fake conditional client.
package fake
import (
	"bytes"
	"context"
	"errors"
	"fmt"
	"io"
	"net/http"
	"sync"
	"cloud.google.com/go/storage"
	"github.com/GoogleCloudPlatform/testgrid/util/gcs"
	"google.golang.org/api/googleapi"
	"google.golang.org/api/iterator"
)
type ConditionalClient struct {
	UploadClient
	read, write *storage.Conditions
	Lock        *sync.RWMutex
}
func (cc *ConditionalClient) check(ctx context.Context, from, to *gcs.Path) error {
	if from != nil && cc.read != nil {
		attrs, err := cc.UploadClient.Stat(ctx, *from)
		if err != nil {
			return err
		}
		if cc.read.GenerationMatch != 0 && cc.read.GenerationMatch != attrs.Generation {
			return fmt.Errorf("bad generation: %w", &googleapi.Error{
				Code: http.StatusPreconditionFailed,
			})
		}
	}
	if to != nil && cc.write != nil {
		attrs, err := cc.UploadClient.Stat(ctx, *to)
		switch {
		case err == storage.ErrObjectNotExist:
			if cc.write.GenerationMatch != 0 {
				return fmt.Errorf("bad generation: %w", &googleapi.Error{
					Code: http.StatusPreconditionFailed,
				})
			}
		case err != nil:
			return err
		case cc.write.GenerationMatch != 0 && cc.write.GenerationMatch != attrs.Generation:
			return fmt.Errorf("bad generation: %w", &googleapi.Error{
				Code: http.StatusPreconditionFailed,
			})
		}
	}
	return nil
}
func (cc *ConditionalClient) Copy(ctx context.Context, from, to gcs.Path) (*storage.ObjectAttrs, error) {
	if cc.Lock != nil {
		cc.Lock.Lock()
		defer cc.Lock.Unlock()
	}
	if err := cc.check(ctx, &from, &to); err != nil {
		return nil, err
	}
	gen := cc.Uploader[to].Generation + 1
	if _, err := cc.UploadClient.Copy(ctx, from, to); err != nil {
		return nil, err
	}
	u := cc.Uploader[to]
	u.Generation = gen
	cc.Uploader[to] = u
	return u.Attrs(to), nil
}
func (cc *ConditionalClient) Upload(ctx context.Context, path gcs.Path, buf []byte, worldRead bool, cache string) (*storage.ObjectAttrs, error) {
	if cc.Lock != nil {
		cc.Lock.Lock()
		defer cc.Lock.Unlock()
	}
	if err := cc.check(ctx, nil, &path); err != nil {
		return nil, err
	}
	gen := cc.Uploader[path].Generation + 1
	_, err := cc.UploadClient.Upload(ctx, path, buf, worldRead, cache)
	if err != nil {
		return nil, err
	}
	u := cc.Uploader[path]
	u.Generation = gen
	cc.Uploader[path] = u
	return u.Attrs(path), nil
}