Browse Source

Add magefile and more generated mocks

Douglas Thrift 1 year ago
parent
commit
781d7f70fb
7 changed files with 198 additions and 1 deletions
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 32 0
      magefiles/magefile.go
  4. 55 0
      neighbors/mocks/ar_ping.go
  5. 49 0
      neighbors/mocks/arp.go
  6. 58 0
      neighbors/mocks/state.go
  7. 1 1
      wrap/mocks/net.go

+ 1 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.17
 
 require (
 	github.com/alecthomas/kong v0.6.1
+	github.com/magefile/mage v1.13.0
 	github.com/stretchr/testify v1.7.5
 	goa.design/clue v0.7.0
 	gopkg.in/yaml.v3 v3.0.1

+ 2 - 0
go.sum

@@ -253,6 +253,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
+github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M=
+github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
 github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
 github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=

+ 32 - 0
magefiles/magefile.go

@@ -0,0 +1,32 @@
+package main
+
+import (
+	"github.com/magefile/mage/sh"
+)
+
+var (
+	Default = Build // nolint: deadcode
+
+	packagesToMock = []string{"neighbors", "wrap"}
+)
+
+// Generate generates mock implementations of interfaces.
+func Generate() (err error) { // nolint: deadcode
+	for _, pkg := range packagesToMock {
+		err = sh.Run("mockery", "--all", "--case=underscore", "--dir="+pkg, "--exported=false", "--output="+pkg+"/mocks")
+		if err != nil {
+			return
+		}
+	}
+	return
+}
+
+// Build builds the binaries.
+func Build() error { // nolint: deadcode
+	return sh.RunV("go", "build", "./cmd/presence")
+}
+
+// Test runs the test suite.
+func Test() error { // nolint: deadcode
+	return sh.RunV("go", "test", "-cover", "-race", "./...")
+}

+ 55 - 0
neighbors/mocks/ar_ping.go

@@ -0,0 +1,55 @@
+// Code generated by mockery v2.14.0. DO NOT EDIT.
+
+package mocks
+
+import (
+	context "context"
+
+	mock "github.com/stretchr/testify/mock"
+)
+
+// ARPing is an autogenerated mock type for the ARPing type
+type ARPing struct {
+	mock.Mock
+}
+
+// Count provides a mock function with given fields: count
+func (_m *ARPing) Count(count uint) {
+	_m.Called(count)
+}
+
+// Ping provides a mock function with given fields: ctx, ifi, hw, ip
+func (_m *ARPing) Ping(ctx context.Context, ifi string, hw string, ip string) (bool, error) {
+	ret := _m.Called(ctx, ifi, hw, ip)
+
+	var r0 bool
+	if rf, ok := ret.Get(0).(func(context.Context, string, string, string) bool); ok {
+		r0 = rf(ctx, ifi, hw, ip)
+	} else {
+		r0 = ret.Get(0).(bool)
+	}
+
+	var r1 error
+	if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok {
+		r1 = rf(ctx, ifi, hw, ip)
+	} else {
+		r1 = ret.Error(1)
+	}
+
+	return r0, r1
+}
+
+type mockConstructorTestingTNewARPing interface {
+	mock.TestingT
+	Cleanup(func())
+}
+
+// NewARPing creates a new instance of ARPing. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+func NewARPing(t mockConstructorTestingTNewARPing) *ARPing {
+	mock := &ARPing{}
+	mock.Mock.Test(t)
+
+	t.Cleanup(func() { mock.AssertExpectations(t) })
+
+	return mock
+}

+ 49 - 0
neighbors/mocks/arp.go

@@ -0,0 +1,49 @@
+// Code generated by mockery v2.14.0. DO NOT EDIT.
+
+package mocks
+
+import (
+	context "context"
+
+	neighbors "douglasthrift.net/presence/neighbors"
+	mock "github.com/stretchr/testify/mock"
+)
+
+// ARP is an autogenerated mock type for the ARP type
+type ARP struct {
+	mock.Mock
+}
+
+// Count provides a mock function with given fields: count
+func (_m *ARP) Count(count uint) {
+	_m.Called(count)
+}
+
+// Present provides a mock function with given fields: ctx, ifs, state, addrStates
+func (_m *ARP) Present(ctx context.Context, ifs neighbors.Interfaces, state neighbors.State, addrStates neighbors.HardwareAddrStates) error {
+	ret := _m.Called(ctx, ifs, state, addrStates)
+
+	var r0 error
+	if rf, ok := ret.Get(0).(func(context.Context, neighbors.Interfaces, neighbors.State, neighbors.HardwareAddrStates) error); ok {
+		r0 = rf(ctx, ifs, state, addrStates)
+	} else {
+		r0 = ret.Error(0)
+	}
+
+	return r0
+}
+
+type mockConstructorTestingTNewARP interface {
+	mock.TestingT
+	Cleanup(func())
+}
+
+// NewARP creates a new instance of ARP. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+func NewARP(t mockConstructorTestingTNewARP) *ARP {
+	mock := &ARP{}
+	mock.Mock.Test(t)
+
+	t.Cleanup(func() { mock.AssertExpectations(t) })
+
+	return mock
+}

+ 58 - 0
neighbors/mocks/state.go

@@ -0,0 +1,58 @@
+// Code generated by mockery v2.14.0. DO NOT EDIT.
+
+package mocks
+
+import mock "github.com/stretchr/testify/mock"
+
+// State is an autogenerated mock type for the State type
+type State struct {
+	mock.Mock
+}
+
+// Changed provides a mock function with given fields:
+func (_m *State) Changed() bool {
+	ret := _m.Called()
+
+	var r0 bool
+	if rf, ok := ret.Get(0).(func() bool); ok {
+		r0 = rf()
+	} else {
+		r0 = ret.Get(0).(bool)
+	}
+
+	return r0
+}
+
+// Present provides a mock function with given fields:
+func (_m *State) Present() bool {
+	ret := _m.Called()
+
+	var r0 bool
+	if rf, ok := ret.Get(0).(func() bool); ok {
+		r0 = rf()
+	} else {
+		r0 = ret.Get(0).(bool)
+	}
+
+	return r0
+}
+
+// Set provides a mock function with given fields: present
+func (_m *State) Set(present bool) {
+	_m.Called(present)
+}
+
+type mockConstructorTestingTNewState interface {
+	mock.TestingT
+	Cleanup(func())
+}
+
+// NewState creates a new instance of State. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+func NewState(t mockConstructorTestingTNewState) *State {
+	mock := &State{}
+	mock.Mock.Test(t)
+
+	t.Cleanup(func() { mock.AssertExpectations(t) })
+
+	return mock
+}

+ 1 - 1
wrap/mocks/net.go

@@ -1,4 +1,4 @@
-// Code generated by mockery v2.13.1. DO NOT EDIT.
+// Code generated by mockery v2.14.0. DO NOT EDIT.
 
 package mocks