bumping test coverage, adding more tests.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-06-16 05:25:26 -04:00
committed by quobix
parent 4b2c0a9b17
commit db27267e09
5 changed files with 75 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/pb33f/libopenapi/index"
@@ -1615,11 +1616,19 @@ x-tacos: [1,2,3]`
}
type test_fresh struct {
val string
val string
thang *bool
}
func (f test_fresh) Hash() [32]byte {
return sha256.Sum256([]byte(f.val))
var data []string
if f.val != "" {
data = append(data, f.val)
}
if f.thang != nil {
data = append(data, fmt.Sprintf("%v", *f.thang))
}
return sha256.Sum256([]byte(strings.Join(data, "|")))
}
func TestAreEqual(t *testing.T) {
assert.True(t, AreEqual(test_fresh{val: "hello"}, test_fresh{val: "hello"}))
@@ -1637,6 +1646,17 @@ func TestGenerateHashString(t *testing.T) {
}
func TestGenerateHashString_Pointer(t *testing.T) {
val := true
assert.Equal(t, "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
GenerateHashString(test_fresh{thang: &val}))
assert.Equal(t, "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b",
GenerateHashString(&val))
}
func TestSetReference(t *testing.T) {
type testObj struct {