Code maintenance: Unix abstraction interface
- Used for creating the tun device if it does not exist - Mocks generated for testing
This commit is contained in:
9
internal/unix/constants.go
Normal file
9
internal/unix/constants.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package unix
|
||||
|
||||
import sysunix "golang.org/x/sys/unix"
|
||||
|
||||
// Constants used for convenience so "os" does not have to be imported
|
||||
|
||||
const (
|
||||
S_IFCHR = sysunix.S_IFCHR
|
||||
)
|
||||
61
internal/unix/mock_unix/unix.go
Normal file
61
internal/unix/mock_unix/unix.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/qdm12/gluetun/internal/unix (interfaces: Unix)
|
||||
|
||||
// Package mock_unix is a generated GoMock package.
|
||||
package mock_unix
|
||||
|
||||
import (
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockUnix is a mock of Unix interface
|
||||
type MockUnix struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockUnixMockRecorder
|
||||
}
|
||||
|
||||
// MockUnixMockRecorder is the mock recorder for MockUnix
|
||||
type MockUnixMockRecorder struct {
|
||||
mock *MockUnix
|
||||
}
|
||||
|
||||
// NewMockUnix creates a new mock instance
|
||||
func NewMockUnix(ctrl *gomock.Controller) *MockUnix {
|
||||
mock := &MockUnix{ctrl: ctrl}
|
||||
mock.recorder = &MockUnixMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockUnix) EXPECT() *MockUnixMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Mkdev mocks base method
|
||||
func (m *MockUnix) Mkdev(arg0, arg1 uint32) uint64 {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Mkdev", arg0, arg1)
|
||||
ret0, _ := ret[0].(uint64)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Mkdev indicates an expected call of Mkdev
|
||||
func (mr *MockUnixMockRecorder) Mkdev(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mkdev", reflect.TypeOf((*MockUnix)(nil).Mkdev), arg0, arg1)
|
||||
}
|
||||
|
||||
// Mknod mocks base method
|
||||
func (m *MockUnix) Mknod(arg0 string, arg1 uint32, arg2 int) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Mknod", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Mknod indicates an expected call of Mknod
|
||||
func (mr *MockUnixMockRecorder) Mknod(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mknod", reflect.TypeOf((*MockUnix)(nil).Mknod), arg0, arg1, arg2)
|
||||
}
|
||||
24
internal/unix/unix.go
Normal file
24
internal/unix/unix.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package unix
|
||||
|
||||
import sysunix "golang.org/x/sys/unix"
|
||||
|
||||
//go:generate mockgen -destination=mock_$GOPACKAGE/$GOFILE . Unix
|
||||
|
||||
type Unix interface {
|
||||
Mkdev(major uint32, minor uint32) uint64
|
||||
Mknod(path string, mode uint32, dev int) (err error)
|
||||
}
|
||||
|
||||
func New() Unix {
|
||||
return &unix{}
|
||||
}
|
||||
|
||||
type unix struct{}
|
||||
|
||||
func (u *unix) Mkdev(major uint32, minor uint32) uint64 {
|
||||
return sysunix.Mkdev(major, minor)
|
||||
}
|
||||
|
||||
func (u *unix) Mknod(path string, mode uint32, dev int) (err error) {
|
||||
return sysunix.Mknod(path, mode, dev)
|
||||
}
|
||||
Reference in New Issue
Block a user