21 lines
512 B
Go
21 lines
512 B
Go
package idempotency
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestHashIsStable(t *testing.T) {
|
||
|
|
first := Hash([]byte(`{"name":"test"}`))
|
||
|
|
second := Hash([]byte(`{"name":"test"}`))
|
||
|
|
if first != second || len(first) != 64 {
|
||
|
|
t.Fatalf("unexpected hashes: %q %q", first, second)
|
||
|
|
}
|
||
|
|
if first == Hash([]byte(`{"name":"other"}`)) {
|
||
|
|
t.Fatal("different bodies should not have the same hash")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestValidateRequest(t *testing.T) {
|
||
|
|
if err := validateRequest(Request{}); err == nil {
|
||
|
|
t.Fatal("empty request should fail")
|
||
|
|
}
|
||
|
|
}
|