Codebase list golang-github-mitchellh-hashstructure / 079c88a
fix: accept interface implementation on pointer matfax authored 5 years ago Mitchell Hashimoto committed 3 years ago
2 changed file(s) with 30 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
8080 // field implements fmt.Stringer
8181 //
8282 func Hash(v interface{}, opts *HashOptions) (uint64, error) {
83 if impl, ok := v.(Hashable); ok {
84 return impl.Hash(), nil
85 }
86
8387 // Create default options
8488 if opts == nil {
8589 opts = &HashOptions{}
589589 }{
590590 {
591591 testHashable{Value: "foo"},
592 &testHashablePointer{Value: "foo"},
593 true,
594 "",
595 },
596
597 {
598 testHashable{Value: "foo1"},
599 &testHashablePointer{Value: "foo2"},
600 true,
601 "",
602 },
603 {
592604 testHashable{Value: "foo"},
593 true,
605 &testHashablePointer{Value: "bar"},
606 false,
594607 "",
595608 },
596
597 {
598 testHashable{Value: "foo1"},
599 testHashable{Value: "foo2"},
600 true,
601 "",
602 },
603 {
604 testHashable{Value: "foo"},
605 testHashable{Value: "bar"},
606 false,
607 "",
608 },
609609 {
610610 testHashable{Value: "nofoo"},
611 testHashable{Value: "bar"},
611 &testHashablePointer{Value: "bar"},
612612 true,
613613 "",
614614 },
695695
696696 return 100, nil
697697 }
698
699 type testHashablePointer struct {
700 Value string
701 }
702
703 func (t *testHashablePointer) Hash() uint64 {
704 if strings.HasPrefix(t.Value, "foo") {
705 return 500
706 }
707 return 100
708 }