Skip to content

Commit

Permalink
libraries/doltcore/row: require.NoError replaces assert.NoError
Browse files Browse the repository at this point in the history
  • Loading branch information
alrs committed Apr 2, 2021
1 parent e5cd14c commit ffe4716
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 63 deletions.
6 changes: 3 additions & 3 deletions go/libraries/doltcore/row/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFmt(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

expected := `first:"rick" | last:"astley" | age:53 | address:"123 Fake St" | title:null_value | `
actual := Fmt(context.Background(), r, sch)
if expected != actual {
t.Errorf("expected: '%s', actual: '%s'", expected, actual)
t.Fatalf("expected: '%s', actual: '%s'", expected, actual)
}
}
74 changes: 37 additions & 37 deletions go/libraries/doltcore/row/noms_row_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func newTestRow() (Row, error) {

func TestItrRowCols(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

itrVals := make(TaggedValues)
_, err = r.IterCols(func(tag uint64, val types.Value) (stop bool, err error) {
itrVals[tag] = val
return false, nil
})
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, TaggedValues{
lnColTag: lnVal,
Expand All @@ -110,25 +110,25 @@ func TestFromNoms(t *testing.T) {
addrColTag: addrVal,
ageColTag: ageVal,
})
assert.NoError(t, err)
require.NoError(t, err)

t.Run("all values specified", func(t *testing.T) {
keys, err := types.NewTuple(types.Format_Default,
types.Uint(fnColTag), fnVal,
types.Uint(lnColTag), lnVal,
)
assert.NoError(t, err)
require.NoError(t, err)

vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
types.Uint(ageColTag), ageVal,
types.Uint(titleColTag), titleVal,
)

assert.NoError(t, err)
require.NoError(t, err)
r, err := FromNoms(sch, keys, vals)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedRow, r)
})

Expand All @@ -137,18 +137,18 @@ func TestFromNoms(t *testing.T) {
types.Uint(fnColTag), fnVal,
types.Uint(lnColTag), lnVal,
)
assert.NoError(t, err)
require.NoError(t, err)

vals, err := types.NewTuple(types.Format_Default)
assert.NoError(t, err)
require.NoError(t, err)

expectedRow, err := New(types.Format_Default, sch, TaggedValues{
fnColTag: fnVal,
lnColTag: lnVal,
})
assert.NoError(t, err)
require.NoError(t, err)
r, err := FromNoms(sch, keys, vals)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedRow, r)
})

Expand All @@ -158,7 +158,7 @@ func TestFromNoms(t *testing.T) {
types.Uint(lnColTag), lnVal,
)

assert.NoError(t, err)
require.NoError(t, err)

vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
Expand All @@ -167,10 +167,10 @@ func TestFromNoms(t *testing.T) {
types.Uint(unusedTag), fnVal,
)

assert.NoError(t, err)
require.NoError(t, err)

r, err := FromNoms(sch, keys, vals)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedRow, r)
})

Expand All @@ -179,12 +179,12 @@ func TestFromNoms(t *testing.T) {
types.Uint(fnColTag), fnVal,
types.Uint(lnColTag), lnVal,
)
assert.NoError(t, err)
require.NoError(t, err)
vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
types.Uint(ageColTag), fnVal,
)
assert.NoError(t, err)
require.NoError(t, err)

_, err = FromNoms(sch, keys, vals)
assert.Error(t, err)
Expand All @@ -195,12 +195,12 @@ func TestFromNoms(t *testing.T) {
types.Uint(fnColTag), fnVal,
types.Uint(lnColTag), lnVal,
)
assert.NoError(t, err)
require.NoError(t, err)
vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
types.Uint(fnColTag), fnVal,
)
assert.NoError(t, err)
require.NoError(t, err)

_, err = FromNoms(sch, keys, vals)
assert.Error(t, err)
Expand All @@ -213,15 +213,15 @@ func TestFromNoms(t *testing.T) {
types.Uint(unusedTag), fnVal,
)

assert.NoError(t, err)
require.NoError(t, err)

vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
types.Uint(ageColTag), ageVal,
types.Uint(titleColTag), titleVal,
)

assert.NoError(t, err)
require.NoError(t, err)

_, err = FromNoms(sch, keys, vals)
assert.Error(t, err)
Expand All @@ -234,14 +234,14 @@ func TestFromNoms(t *testing.T) {
types.Uint(ageColTag), ageVal,
)

assert.NoError(t, err)
require.NoError(t, err)

vals, err := types.NewTuple(types.Format_Default,
types.Uint(addrColTag), addrVal,
types.Uint(titleColTag), titleVal,
)

assert.NoError(t, err)
require.NoError(t, err)

_, err = FromNoms(sch, keys, vals)
assert.Error(t, err)
Expand All @@ -260,17 +260,17 @@ func TestSetColVal(t *testing.T) {
updatedVal := types.String("sanchez")

r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)
r2, err := New(types.Format_Default, sch, expected)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, r, r2)

updated, err := r.SetColVal(lnColTag, updatedVal, sch)
assert.NoError(t, err)
require.NoError(t, err)

// validate calling set does not mutate the original row
r3, err := New(types.Format_Default, sch, expected)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, r, r3)
expected[lnColTag] = updatedVal
r4, err := New(types.Format_Default, sch, expected)
Expand All @@ -279,7 +279,7 @@ func TestSetColVal(t *testing.T) {

// set to a nil value
updated, err = updated.SetColVal(titleColTag, nil, sch)
assert.NoError(t, err)
require.NoError(t, err)
delete(expected, titleColTag)
r5, err := New(types.Format_Default, sch, expected)
require.NoError(t, err)
Expand All @@ -295,27 +295,27 @@ func TestSetColVal(t *testing.T) {
titleColTag: titleVal}

r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

r2, err := New(types.Format_Default, sch, expected)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, r, r2)

// SetColVal allows an incorrect type to be set for a column
updatedRow, err := r.SetColVal(lnColTag, types.Bool(true), sch)
assert.NoError(t, err)
require.NoError(t, err)
// IsValid fails for the type problem
isv, err := IsValid(updatedRow, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, isv)
invalidCol, err := GetInvalidCol(updatedRow, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, invalidCol)
assert.Equal(t, uint64(lnColTag), invalidCol.Tag)

// validate calling set does not mutate the original row
r3, err := New(types.Format_Default, sch, expected)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, r, r3)
})
}
Expand All @@ -324,16 +324,16 @@ func TestConvToAndFromTuple(t *testing.T) {
ctx := context.Background()

r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

keyTpl := r.NomsMapKey(sch).(TupleVals)
valTpl := r.NomsMapValue(sch).(TupleVals)
keyVal, err := keyTpl.Value(ctx)
assert.NoError(t, err)
require.NoError(t, err)
valVal, err := valTpl.Value(ctx)
assert.NoError(t, err)
require.NoError(t, err)
r2, err := FromNoms(sch, keyVal.(types.Tuple), valVal.(types.Tuple))
assert.NoError(t, err)
require.NoError(t, err)

fmt.Println(Fmt(context.Background(), r, sch))
fmt.Println(Fmt(context.Background(), r2, sch))
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestReduceToIndex(t *testing.T) {
expectedIndex, err := New(types.Format_Default, index.Schema(), tvCombo.expectedIndex)
require.NoError(t, err)
indexRow, err := ReduceToIndex(index, row)
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, AreEqual(expectedIndex, indexRow, index.Schema()))
}
}
30 changes: 15 additions & 15 deletions go/libraries/doltcore/row/row_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestGetFieldByName(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

val, ok := GetFieldByName(lnColName, r, sch)

Expand All @@ -47,7 +47,7 @@ func TestGetFieldByName(t *testing.T) {

func TestGetFieldByNameWithDefault(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)
defVal := types.String("default")

val := GetFieldByNameWithDefault(lnColName, defVal, r, sch)
Expand All @@ -65,33 +65,33 @@ func TestGetFieldByNameWithDefault(t *testing.T) {

func TestIsValid(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

isv, err := IsValid(r, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, isv)
invCol, err := GetInvalidCol(r, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.Nil(t, invCol)
column, colConstraint, err := GetInvalidConstraint(r, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.Nil(t, column)
assert.Nil(t, colConstraint)

updatedRow, err := r.SetColVal(lnColTag, nil, sch)
assert.NoError(t, err)
require.NoError(t, err)

isv, err = IsValid(updatedRow, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, isv)

col, err := GetInvalidCol(updatedRow, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, col)
assert.Equal(t, col.Tag, uint64(lnColTag))

col, cnst, err := GetInvalidConstraint(updatedRow, sch)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, col)
assert.Equal(t, col.Tag, uint64(lnColTag))
assert.Equal(t, cnst, schema.NotNullConstraint{})
Expand All @@ -106,27 +106,27 @@ func TestIsValid(t *testing.T) {
require.NoError(t, err)

isv, err := IsValid(r, newSch)
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, isv)

col, err = GetInvalidCol(r, newSch)
assert.NoError(t, err)
require.NoError(t, err)
require.NotNil(t, col)
assert.Equal(t, col.Tag, uint64(addrColTag))

col, cnst, err = GetInvalidConstraint(r, newSch)
assert.NoError(t, err)
require.NoError(t, err)
assert.Nil(t, cnst)
assert.Equal(t, col.Tag, uint64(addrColTag))
})
}

func TestAreEqual(t *testing.T) {
r, err := newTestRow()
assert.NoError(t, err)
require.NoError(t, err)

updatedRow, err := r.SetColVal(lnColTag, types.String("new"), sch)
assert.NoError(t, err)
require.NoError(t, err)

assert.True(t, AreEqual(r, r, sch))
assert.False(t, AreEqual(r, updatedRow, sch))
Expand Down
Loading

0 comments on commit ffe4716

Please sign in to comment.