Skip to content

Commit

Permalink
Add unit test for addr.go (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
matoval authored Aug 2, 2024
1 parent 64047b2 commit a8be816
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/netceptor/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ func (a Addr) Network() string {
func (a Addr) String() string {
return fmt.Sprintf("%s:%s", a.node, a.service)
}

// SetNetwork sets the network variable.
func (a *Addr) SetNetwork(network string) {
a.network = network
}

// SetNetwork sets the node variable.
func (a *Addr) SetNode(node string) {
a.node = node
}

// SetNetwork sets the service variable.
func (a *Addr) SetService(service string) {
a.service = service
}
34 changes: 34 additions & 0 deletions pkg/netceptor/addr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package netceptor_test

import (
"testing"

"github.com/ansible/receptor/pkg/netceptor"
"github.com/ansible/receptor/pkg/netceptor/mock_netceptor"
"github.com/golang/mock/gomock"
)

func TestNetwork(t *testing.T) {
networkResult := "netceptor-testNode1"
strResult := "testNode2:testService"

ctrl := gomock.NewController(t)
mockNetceptor := mock_netceptor.NewMockNetcForPing(ctrl)

mockNetceptor.EXPECT().NewAddr(gomock.Any(), gomock.Any()).Return(netceptor.Addr{})

addr := mockNetceptor.NewAddr("testNode2", "testService")
addr.SetNetwork(networkResult)
addr.SetNode("testNode2")
addr.SetService("testService")

network := addr.Network()
str := addr.String()

if network != networkResult {
t.Errorf("Expected network to be %v, got %v", networkResult, network)
}
if str != strResult {
t.Errorf("Expected network to be %v, got %v", strResult, str)
}
}

0 comments on commit a8be816

Please sign in to comment.