mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-26 16:36:26 -06:00
helper/hashcode for generating hashcodes
This commit is contained in:
parent
6530a0ba2e
commit
3db41fe9f6
10
helper/hashcode/hashcode.go
Normal file
10
helper/hashcode/hashcode.go
Normal file
@ -0,0 +1,10 @@
|
||||
package hashcode
|
||||
|
||||
import (
|
||||
"hash/crc32"
|
||||
)
|
||||
|
||||
// String hashes a string to a unique hashcode.
|
||||
func String(s string) int {
|
||||
return int(crc32.ChecksumIEEE([]byte(s)))
|
||||
}
|
16
helper/hashcode/hashcode_test.go
Normal file
16
helper/hashcode/hashcode_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package hashcode
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
v := "hello, world"
|
||||
expected := String(v)
|
||||
for i := 0; i < 100; i++ {
|
||||
actual := String(v)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user