Repository: etcd-io/etcd
File: tests/robustness/model/describe.go (Go)

Code before:
	case DeleteOperation:
		return fmt.Sprintf("delete(%q)", op.Delete.Key)
	default:
		return fmt.Sprintf("<! unknown op: %q !>", op.Type)
	}
}

func describeRangeRequest(opts RangeOptions, revision int64) string {
	kwargs := []string{}
	if revision != 0 {
		kwargs = append(kwargs, fmt.Sprintf("rev=%d", revision))
	}
	if opts.Limit != 0 {
		kwargs = append(kwargs, fmt.Sprintf("limit=%d", opts.Limit))
	}
	kwargsString := strings.Join(kwargs, ", ")
	if kwargsString != "" {
		kwargsString = ", " + kwargsString
	}
	switch {
	case opts.End == "":
		return fmt.Sprintf("get(%q%s)", opts.Start, kwargsString)
	case opts.End == clientv3.GetPrefixRangeEnd(opts.Start):
		return fmt.Sprintf("list(%q%s)", opts.Start, kwargsString)
	case strings.HasSuffix(opts.Start, "\x00"):
		return fmt.Sprintf("continueList(%q%s)", strings.TrimRight(opts.End, "0\x00"), kwargsString)
	default:
		return fmt.Sprintf("range(%q..%q%s)", opts.Start, opts.End, kwargsString)
	}
}

func describeEtcdOperationResponse(op EtcdOperation, resp EtcdOperationResult) string {
	switch op.Type {
	case RangeOperation:
		return describeRangeResponse(op.Range, resp.RangeResponse)
	case PutOperation:
		return "ok"
	case DeleteOperation:
		return fmt.Sprintf("deleted: %d", resp.Deleted)
	default:
		return fmt.Sprintf("<! unknown op: %q !>", op.Type)
	}
}

func describeRangeResponse(request RangeOptions, response RangeResponse) string {
	if request.End != "" {
		kvs := make([]string, len(response.KVs))
		for i, kv := range response.KVs {
			kvs[i] = describeValueOrHash(kv.Value)
		}
		return fmt.Sprintf("[%s], count: %d", strings.Join(kvs, ","), response.Count)

Review comment (suggestion):
Would prefer to see the opts.Start (without "\x00") over the opts.End here.

So that I can confirm response of 
* `continueList("/registry/a") -> ["/registry/a"]`
* `continueList("/registry/b") -> ["/registry/b"]`

Code after:
	case DeleteOperation:
		return fmt.Sprintf("delete(%q)", op.Delete.Key)
	default:
		return fmt.Sprintf("<! unknown op: %q !>", op.Type)
	}
}

func describeRangeRequest(opts RangeOptions, revision int64) string {
	kwargs := []string{}
	if revision != 0 {
		kwargs = append(kwargs, fmt.Sprintf("rev=%d", revision))
	}
	if opts.Limit != 0 {
		kwargs = append(kwargs, fmt.Sprintf("limit=%d", opts.Limit))
	}
	kwargsString := strings.Join(kwargs, ", ")
	if kwargsString != "" {
		kwargsString = ", " + kwargsString
	}
	switch {
	case opts.End == "":
		return fmt.Sprintf("get(%q%s)", opts.Start, kwargsString)
	case opts.End == clientv3.GetPrefixRangeEnd(opts.Start):
		return fmt.Sprintf("list(%q%s)", opts.Start, kwargsString)
	case strings.HasSuffix(opts.Start, "\x00") && strings.HasSuffix(opts.End, "0") && strings.HasPrefix(opts.Start, opts.End[:len(opts.End)-1]):
		return fmt.Sprintf("list[continued](%q%s)", strings.TrimRight(opts.Start, "\x00"), kwargsString)
	default:
		return fmt.Sprintf("range(%q..%q%s)", opts.Start, opts.End, kwargsString)
	}
}

func describeEtcdOperationResponse(op EtcdOperation, resp EtcdOperationResult) string {
	switch op.Type {
	case RangeOperation:
		return describeRangeResponse(op.Range, resp.RangeResponse)
	case PutOperation:
		return "ok"
	case DeleteOperation:
		return fmt.Sprintf("deleted: %d", resp.Deleted)
	default:
		return fmt.Sprintf("<! unknown op: %q !>", op.Type)
	}
}

func describeRangeResponse(request RangeOptions, response RangeResponse) string {
	if request.End != "" {
		kvs := make([]string, len(response.KVs))
		for i, kv := range response.KVs {
			kvs[i] = describeValueOrHash(kv.Value)
		}
		return fmt.Sprintf("[%s], count: %d", strings.Join(kvs, ","), response.Count)