[SEBA-843] Storing PortNo in the ONU Device struct so that it can be passed with the packetIndications
Change-Id: I28e0bf5721d11fc52d70c6072a6cf70586ba5f98
diff --git a/internal/bbsim/devices/nni_test.go b/internal/bbsim/devices/nni_test.go
new file mode 100644
index 0000000..60856c6
--- /dev/null
+++ b/internal/bbsim/devices/nni_test.go
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/mocking
+package devices
+
+import (
+ "errors"
+ "github.com/opencord/bbsim/internal/bbsim/types"
+ "gotest.tools/assert"
+ "testing"
+)
+
+func TestSetVethUpSuccess(t *testing.T) {
+ spy := &ExecutorSpy{
+ Calls: make(map[int][]string),
+ }
+ err := setVethUp(spy, "test_veth")
+ assert.Equal(t, spy.CommandCallCount, 1)
+ assert.Equal(t, spy.Calls[1][2], "test_veth")
+ assert.Equal(t, err, nil)
+}
+
+func TestSetVethUpFail(t *testing.T) {
+ spy := &ExecutorSpy{
+ failRun: true,
+ Calls: make(map[int][]string),
+ }
+ err := setVethUp(spy, "test_veth")
+ assert.Equal(t, spy.CommandCallCount, 1)
+ assert.Equal(t, err.Error(), "fake-error")
+}
+
+func TestCreateNNIPair(t *testing.T) {
+
+ startDHCPServerCalled := false
+ _startDHCPServer := startDHCPServer
+ defer func() { startDHCPServer = _startDHCPServer }()
+ startDHCPServer = func() error {
+ startDHCPServerCalled = true
+ return nil
+ }
+
+ listenOnVethCalled := false
+ _listenOnVeth := listenOnVeth
+ defer func() { listenOnVeth = _listenOnVeth }()
+ listenOnVeth = func(vethName string) (chan *types.PacketMsg, error) {
+ listenOnVethCalled = true
+ return make(chan *types.PacketMsg, 1), nil
+ }
+ spy := &ExecutorSpy{
+ failRun: false,
+ Calls: make(map[int][]string),
+ }
+
+ olt := OltDevice{}
+
+ err := createNNIPair(spy, &olt)
+
+ assert.Equal(t, spy.CommandCallCount, 3)
+ assert.Equal(t, startDHCPServerCalled, true)
+ assert.Equal(t, listenOnVethCalled, true)
+ assert.Equal(t, err, nil)
+ assert.Assert(t, olt.nniPktInChannel != nil)
+}
+
+type ExecutorSpy struct {
+ failRun bool
+
+ CommandCallCount int
+ RunCallCount int
+ Calls map[int][]string
+}
+
+func (s *ExecutorSpy) Command(name string, arg ...string) Runnable {
+ s.CommandCallCount++
+
+ s.Calls[s.CommandCallCount] = arg
+
+ return s
+}
+
+func (s *ExecutorSpy) Run() error {
+ s.RunCallCount++
+ if s.failRun {
+ return errors.New("fake-error")
+ }
+ return nil
+}