Skip to content

Commit

Permalink
reservedipv6: add mock Manager and actioner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anitgandhi committed Dec 17, 2024
1 parent 45f8c92 commit 158748f
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,4 @@ mockgen:
GOOS=linux mockgen -source=internal/netutil/tcp_sniffer_helper_linux.go -package=mocks -destination=internal/netutil/internal/mocks/dependent_functions_mock.go
mockgen -source=internal/metadata/updater/updater.go -package=updater -destination=internal/metadata/updater/updater_mocks.go
mockgen -destination=internal/metadata/updater/readcloser_mocks.go -package=updater -build_flags=--mod=mod io ReadCloser
mockgen -typed -source=internal/reservedipv6/reserved_ipv6.go -package=reservedipv6 -destination=internal/reservedipv6/mocks.go
54 changes: 54 additions & 0 deletions internal/metadata/actioner/reserved_ipv6_actioner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: Apache-2.0

package actioner

import (
"testing"

"github.com/digitalocean/droplet-agent/internal/metadata"
"github.com/digitalocean/droplet-agent/internal/reservedipv6"
"go.uber.org/mock/gomock"
)

func TestReservedIPv6Actioner_Do(t *testing.T) {
t.Run("assign", func(t *testing.T) {
// Arrange
ctrl := gomock.NewController(t)
defer ctrl.Finish()

rip6Manager := reservedipv6.NewMockManager(ctrl)
actioner := NewReservedIPv6Actioner(rip6Manager)

rip6Manager.EXPECT().Assign("2001:4860:4860::8888").Return(nil)

// Act
actioner.Do(&metadata.Metadata{
ReservedIP: &metadata.ReservedIP{
IPv6: &metadata.ReservedIPv6{
Active: true,
IPAddress: "2001:4860:4860::8888",
},
},
})
})

t.Run("unassign", func(t *testing.T) {
// Arrange
ctrl := gomock.NewController(t)
defer ctrl.Finish()

rip6Manager := reservedipv6.NewMockManager(ctrl)
actioner := NewReservedIPv6Actioner(rip6Manager)

rip6Manager.EXPECT().Unassign().Return(nil)

// Act
actioner.Do(&metadata.Metadata{
ReservedIP: &metadata.ReservedIP{
IPv6: &metadata.ReservedIPv6{
Active: false,
},
},
})
})
}
114 changes: 114 additions & 0 deletions internal/reservedipv6/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/reservedipv6/reserved_ipv6.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

package reservedipv6

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/reservedipv6/reserved_ipv6_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

package reservedipv6

var _ Manager = (*mgr)(nil)

0 comments on commit 158748f

Please sign in to comment.