github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/repo/testdb/assertions.go (about) 1 package testdb 2 3 import ( 4 "database/sql" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 // AssertSQLNullStringEqualTo is a helper to check if the sql.NullString is equal to the given string. 12 func AssertSQLNullStringEqualTo(t *testing.T, in sql.NullString, text *string) { 13 if text != nil { 14 sqlStr := sql.NullString{} 15 err := sqlStr.Scan(*text) 16 require.NoError(t, err) 17 assert.Equal(t, in, sqlStr) 18 } else { 19 require.False(t, in.Valid) 20 } 21 } 22 23 // AssertSQLNullBool is a helper to check if the sql.NullBool is equal to the given bool. 24 func AssertSQLNullBool(t *testing.T, in sql.NullBool, boolean *bool) { 25 if boolean != nil { 26 require.True(t, in.Valid) 27 assert.Equal(t, *boolean, in.Bool) 28 } else { 29 assert.False(t, in.Valid) 30 } 31 }