Skip to content

Commit

Permalink
Rebase against master
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-milkey committed Jan 29, 2021
1 parent bc43cc8 commit beabf10
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Expand Up @@ -45,3 +45,5 @@ issues:
- scopelint
- path: pkg/manager
text: "is unused"
- path: pkg/northbound/gnmi/subscribe_test.go
text: "is unused"
26 changes: 13 additions & 13 deletions pkg/modelregistry/jsonvalues/jsonToValues_test.go
Expand Up @@ -19,7 +19,7 @@ import (
devicechange "github.com/onosproject/onos-api/go/onos/config/change/device"
"github.com/onosproject/onos-config/pkg/modelregistry"
"github.com/openconfig/goyang/pkg/yang"
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
Expand All @@ -42,12 +42,12 @@ func setUpRwPaths() (modelregistry.ReadOnlyPathMap, modelregistry.ReadWritePathM

func Test_DecomposeTree(t *testing.T) {
sampleTree, err := setUpJSONToValues("./testdata/sample-tree-from-devicesim.json")
assert.NilError(t, err)
assert.Assert(t, len(sampleTree) > 0, "Empty sample tree", len(sampleTree))
assert.NoError(t, err)
assert.True(t, len(sampleTree) > 0, "Empty sample tree", len(sampleTree))

ds1RoPaths, _ := setUpRwPaths()
pathValues, err := DecomposeJSONWithPaths("", sampleTree, ds1RoPaths, nil)
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, len(pathValues), 24)

for _, pathValue := range pathValues {
Expand Down Expand Up @@ -91,12 +91,12 @@ func Test_DecomposeTree(t *testing.T) {
// We also test that when a RO path is given in the JSON that it is ignored
func Test_DecomposeTreeConfigOnly(t *testing.T) {
sampleTree, err := setUpJSONToValues("./testdata/sample-tree-double-key.json")
assert.NilError(t, err)
assert.Assert(t, len(sampleTree) > 0, "Empty sample tree %d", len(sampleTree))
assert.NoError(t, err)
assert.True(t, len(sampleTree) > 0, "Empty sample tree %d", len(sampleTree))

_, ds1RwPaths := setUpRwPaths()
pathValues, err := DecomposeJSONWithPaths("/system/logging/remote-servers", sampleTree, nil, ds1RwPaths)
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, len(pathValues), 6)

for _, v := range pathValues {
Expand Down Expand Up @@ -127,7 +127,7 @@ func Test_findModelRwPathNoIndices(t *testing.T) {
rwElem, fullpath, ok := findModelRwPathNoIndices(ds1RwPaths, jsonPath)
assert.Equal(t, true, ok)
assert.Equal(t, modelPath, fullpath)
assert.Assert(t, rwElem != nil, "rwElem map not expected to be nil")
assert.NotNil(t, rwElem, "rwElem map not expected to be nil")
assert.Equal(t, devicechange.ValueType_STRING, rwElem.ValueType)
}

Expand All @@ -139,7 +139,7 @@ func Test_findModelRoPathNoIndices(t *testing.T) {
roAttr, fullpath, ok := findModelRoPathNoIndices(ds1RoPaths, jsonPath)
assert.Equal(t, true, ok)
assert.Equal(t, modelPath, fullpath)
assert.Assert(t, roAttr != nil, "roAttr map not expected to be nil")
assert.NotNil(t, roAttr, "roAttr map not expected to be nil")
assert.Equal(t, devicechange.ValueType_STRING, roAttr.ValueType)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ func Test_insertNumericalIndices(t *testing.T) {
const jsonPath = "/p/q/r[10]/s/t[20]/u/v[30]/w"
const expected = "/p/q/r[a=10]/s/t[b=20][c=20]/u/v[d=30][e=30][f=30]/w"
replaced, err := insertNumericalIndices(modelPath, jsonPath)
assert.NilError(t, err, "unexpected error replacing wildcards")
assert.NoError(t, err, "unexpected error replacing wildcards")
assert.Equal(t, expected, replaced)
}

Expand All @@ -176,7 +176,7 @@ func Test_insertNumericalIndicesNoIdx(t *testing.T) {
const jsonPath = "/l/m/n/o"
const expected = "/l/m/n/o"
replaced, err := insertNumericalIndices(modelPath, jsonPath)
assert.NilError(t, err, "unexpected error replacing wildcards")
assert.NoError(t, err, "unexpected error replacing wildcards")
assert.Equal(t, expected, replaced)
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func Test_replaceIndices(t *testing.T) {
indices = append(indices, indexValue{"e", devicechange.NewTypedValueString("9"), 4})
indices = append(indices, indexValue{"f", devicechange.NewTypedValueString("10"), 5})
replaced, err := replaceIndices(modelPathNumericalIdx, len(modelPathNumericalIdx), indices)
assert.NilError(t, err, "unexpected error replacing numbers")
assert.NoError(t, err, "unexpected error replacing numbers")
assert.Equal(t, modelPathExpected, replaced, "unexpected value after replacing numbers")
}

Expand All @@ -221,7 +221,7 @@ func Test_replaceIndices2(t *testing.T) {
indices = append(indices, indexValue{"f", devicechange.NewTypedValueString("10"), 6})

replaced, err := replaceIndices(modelPathNumericalIdx, 57, indices)
assert.NilError(t, err, "unexpected error replacing numbers")
assert.NoError(t, err, "unexpected error replacing numbers")
assert.Equal(t, modelPathExpected, replaced, "unexpected value after replacing numbers")
}

Expand Down
53 changes: 28 additions & 25 deletions pkg/northbound/gnmi/set_test.go
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/onosproject/onos-config/pkg/utils"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/gnmi/proto/gnmi_ext"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gotest.tools/assert"
"regexp"
"strconv"
"testing"
Expand Down Expand Up @@ -108,10 +108,10 @@ func Test_doSingleSet(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 1)

Expand Down Expand Up @@ -168,10 +168,10 @@ func Test_doSingleSetList(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 1)

Expand Down Expand Up @@ -223,10 +223,10 @@ func Test_do2SetsOnSameTarget(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 2)

Expand All @@ -241,11 +241,11 @@ func Test_do2SetsOnSameTarget(t *testing.T) {
assert.Equal(t, 1, len(setResponse.Extension))
assert.Equal(t, 100, int(setResponse.Extension[0].GetRegisteredExt().Id))
changeUUID := string(setResponse.Extension[0].GetRegisteredExt().GetMsg())
assert.Assert(t, uuidRegex.MatchString(changeUUID), "ID does not match %s", uuidRegex.String())
assert.True(t, uuidRegex.MatchString(changeUUID), "ID does not match %s", uuidRegex.String())

// Check the network change was made
nwChange, err := mgr.NetworkChangesStore.Get(networkchange.ID(changeUUID))
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, 1, len(nwChange.Changes))
changes := nwChange.Changes[0]
assert.Equal(t, "localhost-1", string(changes.DeviceID))
Expand Down Expand Up @@ -290,10 +290,10 @@ func Test_do2SetsOnDiffTargets(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 2)

Expand All @@ -306,11 +306,11 @@ func Test_do2SetsOnDiffTargets(t *testing.T) {
assert.Equal(t, 1, len(setResponse.Extension))
assert.Equal(t, 100, int(setResponse.Extension[0].GetRegisteredExt().Id))
changeUUID := string(setResponse.Extension[0].GetRegisteredExt().GetMsg())
assert.Assert(t, uuidRegex.MatchString(changeUUID), "ID does not match %s", uuidRegex.String())
assert.True(t, uuidRegex.MatchString(changeUUID), "ID does not match %s", uuidRegex.String())

// Check the network change was made
nwChange, err := mgr.NetworkChangesStore.Get(networkchange.ID(changeUUID))
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, 2, len(nwChange.Changes))
for _, ch := range nwChange.Changes {
assert.Equal(t, "TestDevice", string(ch.DeviceType))
Expand Down Expand Up @@ -370,10 +370,10 @@ func Test_do2SetsOnOneTargetOneOnDiffTarget(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 4)

Expand Down Expand Up @@ -413,10 +413,10 @@ func Test_doSingleDelete(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to exist")
assert.NotNil(t, setResponse, "Expected setResponse to exist")

assert.Equal(t, len(setResponse.Response), 1)

Expand Down Expand Up @@ -474,10 +474,10 @@ func Test_doUpdateDeleteSet(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.NilError(t, setError, "Unexpected error from gnmi Set")
assert.NoError(t, setError, "Unexpected error from gnmi Set")

// Check that Response is correct
assert.Assert(t, setResponse != nil, "Expected setResponse to have a value")
assert.NotNil(t, setResponse, "Expected setResponse to have a value")

assert.Equal(t, len(setResponse.Response), 2)

Expand Down Expand Up @@ -573,8 +573,9 @@ func TestSet_MissingDeviceType(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.ErrorContains(t, setError, "NoSuchDevice is not known")
assert.Assert(t, setResponse == nil)
assert.Error(t, setError)
assert.Contains(t, setError.Error(), "NoSuchDevice is not known")
assert.Nil(t, setResponse)
}

// Tests giving a device with multiple versions where the request doesn't specify which one
Expand Down Expand Up @@ -602,8 +603,9 @@ func TestSet_ConflictingDeviceType(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.ErrorContains(t, setError, "Specify 1 version with extension 102")
assert.Assert(t, setResponse == nil)
assert.Error(t, setError)
assert.Contains(t, setError.Error(), "Specify 1 version with extension 102")
assert.Nil(t, setResponse)
}

// Test giving a device with a type that doesn't match the type in the store
Expand Down Expand Up @@ -641,6 +643,7 @@ func TestSet_BadDeviceType(t *testing.T) {

setResponse, setError := server.Set(context.Background(), &setRequest)

assert.ErrorContains(t, setError, "target DeviceWithMultipleVersions type given NotTheSameType does not match expected TestDevice")
assert.Assert(t, setResponse == nil)
assert.Error(t, setError)
assert.Contains(t, setError.Error(), "target DeviceWithMultipleVersions type given NotTheSameType does not match expected TestDevice")
assert.Nil(t, setResponse)
}

0 comments on commit beabf10

Please sign in to comment.