github.com/d-luu/terraform@v0.11.12-beta1/helper/hashcode/hashcode_test.go (about)

     1  package hashcode
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestString(t *testing.T) {
     8  	v := "hello, world"
     9  	expected := String(v)
    10  	for i := 0; i < 100; i++ {
    11  		actual := String(v)
    12  		if actual != expected {
    13  			t.Fatalf("bad: %#v\n\t%#v", actual, expected)
    14  		}
    15  	}
    16  }
    17  
    18  func TestStrings(t *testing.T) {
    19  	v := []string{"hello", ",", "world"}
    20  	expected := Strings(v)
    21  	for i := 0; i < 100; i++ {
    22  		actual := Strings(v)
    23  		if actual != expected {
    24  			t.Fatalf("bad: %#v\n\t%#v", actual, expected)
    25  		}
    26  	}
    27  }
    28  
    29  func TestString_positiveIndex(t *testing.T) {
    30  	// "2338615298" hashes to uint32(2147483648) which is math.MinInt32
    31  	ips := []string{"192.168.1.3", "192.168.1.5", "2338615298"}
    32  	for _, ip := range ips {
    33  		if index := String(ip); index < 0 {
    34  			t.Fatalf("Bad Index %#v for ip %s", index, ip)
    35  		}
    36  	}
    37  }