|
| 1 | +// Copyright 2014 The Cockroach Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | +// implied. See the License for the specific language governing |
| 13 | +// permissions and limitations under the License. See the AUTHORS file |
| 14 | +// for names of contributors. |
| 15 | +// |
| 16 | +// Author: Veteran Lu (23907238@qq.com) |
| 17 | + |
| 18 | +package roachpb |
| 19 | + |
| 20 | +import "testing" |
| 21 | + |
| 22 | +// TestBatchRequestGetArg tests that the method for BatchRequest.GetArg |
| 23 | +func TestBatchRequestGetArg(t *testing.T) { |
| 24 | + testCases := []struct { |
| 25 | + bu []RequestUnion |
| 26 | + exp bool |
| 27 | + }{ |
| 28 | + {[]RequestUnion{}, false}, |
| 29 | + {[]RequestUnion{{Get: &GetRequest{}}}, false}, |
| 30 | + {[]RequestUnion{{EndTransaction: &EndTransactionRequest{}}, {Get: &GetRequest{}}}, false}, |
| 31 | + {[]RequestUnion{{EndTransaction: &EndTransactionRequest{}}}, true}, |
| 32 | + {[]RequestUnion{{Get: &GetRequest{}}, {EndTransaction: &EndTransactionRequest{}}}, true}, |
| 33 | + } |
| 34 | + |
| 35 | + for i, c := range testCases { |
| 36 | + br := BatchRequest{Requests: c.bu} |
| 37 | + if _, r := br.GetArg(EndTransaction); r != c.exp { |
| 38 | + t.Errorf("%d: unexpected next bytes for %v: %v", i, c.bu, c.exp) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments