package crypto import ( "encoding/hex" "fmt" "testing" ) func TestNewSHA256(t *testing.T) { for i, tt := range []struct { in []byte out string }{ {[]byte(""), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, {[]byte("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}, {[]byte("hello"), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"}, } { t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { result := NewSHA256(tt.in) if hex.EncodeToString(result) != tt.out { t.Errorf("want %v; got %v", tt.out, hex.EncodeToString(result)) } }) } }