...

Source file src/github.com/gomodule/redigo/redis/list_test.go

Documentation: github.com/gomodule/redigo/redis

     1  // Copyright 2018 Gary Burd
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // 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, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  // +build go1.9
    16  
    17  package redis
    18  
    19  import "testing"
    20  
    21  func TestPoolList(t *testing.T) {
    22  	var idle idleList
    23  	var a, b, c poolConn
    24  
    25  	check := func(pcs ...*poolConn) {
    26  		if idle.count != len(pcs) {
    27  			t.Fatal("idle.count != len(pcs)")
    28  		}
    29  		if len(pcs) == 0 {
    30  			if idle.front != nil {
    31  				t.Fatalf("front not nil")
    32  			}
    33  			if idle.back != nil {
    34  				t.Fatalf("back not nil")
    35  			}
    36  			return
    37  		}
    38  		if idle.front != pcs[0] {
    39  			t.Fatal("front != pcs[0]")
    40  		}
    41  		if idle.back != pcs[len(pcs)-1] {
    42  			t.Fatal("back != pcs[len(pcs)-1]")
    43  		}
    44  		if idle.front.prev != nil {
    45  			t.Fatal("front.prev != nil")
    46  		}
    47  		if idle.back.next != nil {
    48  			t.Fatal("back.next != nil")
    49  		}
    50  		for i := 1; i < len(pcs)-1; i++ {
    51  			if pcs[i-1].next != pcs[i] {
    52  				t.Fatal("pcs[i-1].next != pcs[i]")
    53  			}
    54  			if pcs[i+1].prev != pcs[i] {
    55  				t.Fatal("pcs[i+1].prev != pcs[i]")
    56  			}
    57  		}
    58  	}
    59  
    60  	idle.pushFront(&c)
    61  	check(&c)
    62  	idle.pushFront(&b)
    63  	check(&b, &c)
    64  	idle.pushFront(&a)
    65  	check(&a, &b, &c)
    66  	idle.popFront()
    67  	check(&b, &c)
    68  	idle.popFront()
    69  	check(&c)
    70  	idle.popFront()
    71  	check()
    72  
    73  	idle.pushFront(&c)
    74  	check(&c)
    75  	idle.pushFront(&b)
    76  	check(&b, &c)
    77  	idle.pushFront(&a)
    78  	check(&a, &b, &c)
    79  	idle.popBack()
    80  	check(&a, &b)
    81  	idle.popBack()
    82  	check(&a)
    83  	idle.popBack()
    84  	check()
    85  }
    86  

View as plain text