github.com/opentofu/opentofu@v1.7.1/internal/legacy/helper/hashcode/hashcode_test.go (about)

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