github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/legacy/helper/hashcode/hashcode_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package hashcode 5 6 import ( 7 "testing" 8 ) 9 10 func TestString(t *testing.T) { 11 v := "hello, world" 12 expected := String(v) 13 for i := 0; i < 100; i++ { 14 actual := String(v) 15 if actual != expected { 16 t.Fatalf("bad: %#v\n\t%#v", actual, expected) 17 } 18 } 19 } 20 21 func TestStrings(t *testing.T) { 22 v := []string{"hello", ",", "world"} 23 expected := Strings(v) 24 for i := 0; i < 100; i++ { 25 actual := Strings(v) 26 if actual != expected { 27 t.Fatalf("bad: %#v\n\t%#v", actual, expected) 28 } 29 } 30 } 31 32 func TestString_positiveIndex(t *testing.T) { 33 // "2338615298" hashes to uint32(2147483648) which is math.MinInt32 34 ips := []string{"192.168.1.3", "192.168.1.5", "2338615298"} 35 for _, ip := range ips { 36 if index := String(ip); index < 0 { 37 t.Fatalf("Bad Index %#v for ip %s", index, ip) 38 } 39 } 40 }