diff --git a/pkg/ipmi/handler.go b/pkg/ipmi/handler.go index 4275f5d6c8a..af2c992506d 100644 --- a/pkg/ipmi/handler.go +++ b/pkg/ipmi/handler.go @@ -36,10 +36,3 @@ func (r *realSyscalls) fileSetReadDeadline(f *os.File, t time.Duration) error { func (r *realSyscalls) connRead(f func(fd uintptr) bool, conn syscall.RawConn) error { return conn.Read(f) } - -type handler interface { - SendRequest(*request) error - ReceiveResponse(int64, *response, []byte) ([]byte, error) - File() *os.File - Close() error -} diff --git a/pkg/ipmi/ipmi.go b/pkg/ipmi/ipmi.go index bb083e365b0..f49f862e943 100644 --- a/pkg/ipmi/ipmi.go +++ b/pkg/ipmi/ipmi.go @@ -30,7 +30,7 @@ var ( // IPMI represents access to the IPMI interface. type IPMI struct { - handler + *dev } // SendRecv sends the IPMI message, receives the response, and returns the @@ -66,7 +66,7 @@ func (i *IPMI) RawSendRecv(msg Msg) ([]byte, error) { // Send request. for { - switch err := i.handler.SendRequest(req); { + switch err := i.dev.SendRequest(req); { case err == syscall.EINTR: continue case err != nil: @@ -86,7 +86,7 @@ func (i *IPMI) RawSendRecv(msg Msg) ([]byte, error) { msg: recvMsg, } - return i.handler.ReceiveResponse(req.msgid, recv, buf) + return i.dev.ReceiveResponse(req.msgid, recv, buf) } func (i *IPMI) WatchdogRunning() (bool, error) { @@ -352,5 +352,5 @@ func (i *IPMI) RawCmd(param []byte) ([]byte, error) { // Close closes the file attached to ipmi func (i *IPMI) Close() error { - return i.handler.Close() + return i.dev.Close() } diff --git a/pkg/ipmi/ipmi_linux.go b/pkg/ipmi/ipmi_linux.go index e524759e993..80576534326 100644 --- a/pkg/ipmi/ipmi_linux.go +++ b/pkg/ipmi/ipmi_linux.go @@ -18,5 +18,5 @@ func Open(devnum int) (*IPMI, error) { return nil, err } - return &IPMI{handler: newDev(f)}, nil + return &IPMI{dev: newDev(f)}, nil } diff --git a/pkg/ipmi/ipmi_test.go b/pkg/ipmi/ipmi_test.go deleted file mode 100644 index 48475490a35..00000000000 --- a/pkg/ipmi/ipmi_test.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2022 the u-root Authors. All rights reserved -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ipmi - -import ( - "testing" -) - -func TestWatchdogRunning(t *testing.T) { - i := getMockIPMI() - if _, err := i.WatchdogRunning(); err != nil { - t.Errorf(`i.WatchdogRunning() = nil, not %q`, err) - } - -} -func TestShutoffWatchdog(t *testing.T) { - i := getMockIPMI() - if err := i.ShutoffWatchdog(); err != nil { - t.Errorf(`i.ShutoffWatchdog() = nil, not %q`, err) - } -} -func TestGetDeviceID(t *testing.T) { - i := getMockIPMI() - if _, err := i.GetDeviceID(); err != nil { - t.Errorf(`i.GetDeviceID() = nil, not %q`, err) - } -} -func TestEnableSEL(t *testing.T) { - i := getMockIPMI() - if _, err := i.EnableSEL(); err != nil { - t.Errorf(`i.EnableSEL() = nil, not %q`, err) - } -} - -func TestGetSELInfo(t *testing.T) { - i := getMockIPMI() - if _, err := i.GetSELInfo(); err != nil { - t.Errorf(`i.GetSELInfo() = nil, not %q`, err) - } -} -func TestGetLanConfig(t *testing.T) { - i := getMockIPMI() - if _, err := i.GetLanConfig(1, 1); err != nil { - t.Errorf(`i.GetLanConfig(1, 1) = nil, not %q`, err) - } -} -func TestRawCmd(t *testing.T) { - i := getMockIPMI() - data := []byte{0x1, 0x2, 0x3} - if _, err := i.RawCmd(data); err != nil { - t.Errorf(`i.RawCmd(data) = nil, not %q`, err) - } -} -func TestSetSystemFWVersion(t *testing.T) { - i := getMockIPMI() - if err := i.SetSystemFWVersion("TestTest"); err != nil { - t.Errorf(`i.SetSystemFWVersion("TestTest") = nil, not %q`, err) - } -} -func TestLogSystemEvent(t *testing.T) { - i := getMockIPMI() - e := &Event{} - if err := i.LogSystemEvent(e); err != nil { - t.Errorf(`i.LogSystemEvent(e) = nil, not %q`, err) - } -} diff --git a/pkg/ipmi/mock.go b/pkg/ipmi/mock.go deleted file mode 100644 index e68fde94b46..00000000000 --- a/pkg/ipmi/mock.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2019-2022 the u-root Authors. All rights reserved -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ipmi - -import ( - "os" - "syscall" - "time" - - "golang.org/x/sys/unix" -) - -// mock is for testing purposes only -type mock struct { - unixSyscall func(uintptr, uintptr, uintptr, uintptr) (uintptr, uintptr, unix.Errno) - - // fileSyscallConn gives the option to overwrite the actual function call with a dummy function when writing tests. - fileSyscallConn func(f *os.File) (syscall.RawConn, error) - - // fileSetReadDeadline gives the option to overwrite the actual function call with a dummy function when writing tests. - fileSetReadDeadline func(f *os.File, t time.Duration) error - - // connRead gives the option to overwrite the actual function call with a dummy function when writing tests. - connRead func(f func(fd uintptr) bool, conn syscall.RawConn) error -} - -func (m *mock) SendRequest(req *request) error { - return nil -} - -func (m *mock) ReceiveResponse(msgID int64, resp *response, buf []byte) ([]byte, error) { - return buf, nil -} - -func (m *mock) File() *os.File { - return nil -} - -func (m *mock) Close() error { - return nil -} - -func getMockIPMI() *IPMI { - return &IPMI{handler: &mock{}} -}