Files
object-browser/restapi/ws_handle_test.go
César Nieto 8e9bd8728a Add mcs admin trace api (#82)
Trace Api uses websocket to send trace information, a
valid jwt token needs to be sent either on the header
or as a cookie of the ws request to start.
Three goroutines are needed to ensure communication
if read hearbeat fails all trace should stop by cancelling
the context. WaitGroups are needed to ensure all
goroutines finish gracefully.
2020-04-30 10:50:51 -07:00

69 lines
2.1 KiB
Go

// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package restapi
import (
"time"
)
// Common mocks for WSConn interface
// assigning mock at runtime instead of compile time
var connWriteMessageMock func(messageType int, data []byte) error
var connReadMessageMock func() (messageType int, p []byte, err error)
// Uncomment and implement if needed
// var connCloseMock func() error
// var connSetReadLimitMock func(limit int64)
// var connSetReadDeadlineMock func(t time.Time) error
// var connSetPongHandlerMock func(h func(appData string) error)
// The Conn type represents a WebSocket connection.
type mockConn struct{}
func (c mockConn) writeMessage(messageType int, data []byte) error {
return connWriteMessageMock(messageType, data)
}
func (c mockConn) readMessage() (messageType int, p []byte, err error) {
return connReadMessageMock()
}
func (c mockConn) close() error {
return nil
}
func (c mockConn) setReadLimit(limit int64) {
}
func (c mockConn) setReadDeadline(t time.Time) error {
return nil
}
func (c mockConn) setPongHandler(h func(appData string) error) {
}
// Common mocks for MCSWebsocket interface
// assigning mock at runtime instead of compile time
var wsTraceMock func()
// Define a mock struct of wsClient interface implementation
type wsClientMock struct {
// MinIO admin Client
madmin MinioAdmin
}
// mock function of wsc.trace()
func (wsc wsClientMock) trace() {
wsTraceMock()
}