Fixed lint issues with files (#3234)

Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2024-02-12 23:55:17 -06:00
committed by GitHub
parent f394cb69ce
commit 80c03839a4
65 changed files with 438 additions and 449 deletions

View File

@@ -39,7 +39,7 @@ func TestArnsList(t *testing.T) {
assert := asrt.New(t) assert := asrt.New(t)
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
// Test-1 : getArns() returns proper arn list // Test-1 : getArns() returns proper arn list
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{ return madmin.InfoMessage{
SQSARN: []string{"uno"}, SQSARN: []string{"uno"},
}, nil }, nil
@@ -54,7 +54,7 @@ func TestArnsList(t *testing.T) {
assert.Nil(err, "Error should have been nil") assert.Nil(err, "Error should have been nil")
// Test-2 : getArns(ctx) fails for whatever reason // Test-2 : getArns(ctx) fails for whatever reason
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{}, errors.New("some reason") return madmin.InfoMessage{}, errors.New("some reason")
} }

View File

@@ -269,7 +269,6 @@ func resetConfigResponse(session *models.Principal, params cfgApi.ResetConfigPar
adminClient := AdminClient{Client: mAdmin} adminClient := AdminClient{Client: mAdmin}
err = resetConfig(ctx, adminClient, &params.Name) err = resetConfig(ctx, adminClient, &params.Name)
if err != nil { if err != nil {
return nil, ErrorWithContext(ctx, err) return nil, ErrorWithContext(ctx, err)
} }

View File

@@ -63,7 +63,7 @@ func TestListConfig(t *testing.T) {
} }
expectedKeysDesc := mockConfigList.KeysHelp expectedKeysDesc := mockConfigList.KeysHelp
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return mockConfigList, nil return mockConfigList, nil
} }
configList, err := listConfig(adminClient) configList, err := listConfig(adminClient)
@@ -80,7 +80,7 @@ func TestListConfig(t *testing.T) {
// Test-2 : listConfig() Return error and see that the error is handled correctly and returned // Test-2 : listConfig() Return error and see that the error is handled correctly and returned
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{}, errors.New("error") return madmin.Help{}, errors.New("error")
} }
_, err = listConfig(adminClient) _, err = listConfig(adminClient)
@@ -94,7 +94,7 @@ func TestSetConfig(t *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
function := "setConfig()" function := "setConfig()"
// mock function response from setConfig() // mock function response from setConfig()
minioSetConfigKVMock = func(kv string) (restart bool, err error) { minioSetConfigKVMock = func(_ string) (restart bool, err error) {
return false, nil return false, nil
} }
configName := "notify_postgres" configName := "notify_postgres"
@@ -119,7 +119,7 @@ func TestSetConfig(t *testing.T) {
assert.Equal(restart, false) assert.Equal(restart, false)
// Test-2 : setConfig() returns error, handle properly // Test-2 : setConfig() returns error, handle properly
minioSetConfigKVMock = func(kv string) (restart bool, err error) { minioSetConfigKVMock = func(_ string) (restart bool, err error) {
return false, errors.New("error") return false, errors.New("error")
} }
restart, err = setConfig(ctx, adminClient, &configName, kvs) restart, err = setConfig(ctx, adminClient, &configName, kvs)
@@ -129,7 +129,7 @@ func TestSetConfig(t *testing.T) {
assert.Equal(restart, false) assert.Equal(restart, false)
// Test-4 : setConfig() set config, need restart // Test-4 : setConfig() set config, need restart
minioSetConfigKVMock = func(kv string) (restart bool, err error) { minioSetConfigKVMock = func(_ string) (restart bool, err error) {
return true, nil return true, nil
} }
restart, err = setConfig(ctx, adminClient, &configName, kvs) restart, err = setConfig(ctx, adminClient, &configName, kvs)
@@ -144,7 +144,7 @@ func TestDelConfig(t *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
function := "resetConfig()" function := "resetConfig()"
// mock function response from setConfig() // mock function response from setConfig()
minioDelConfigKVMock = func(name string) (err error) { minioDelConfigKVMock = func(_ string) (err error) {
return nil return nil
} }
configName := "region" configName := "region"
@@ -158,7 +158,7 @@ func TestDelConfig(t *testing.T) {
} }
// Test-2 : resetConfig() returns error, handle properly // Test-2 : resetConfig() returns error, handle properly
minioDelConfigKVMock = func(name string) (err error) { minioDelConfigKVMock = func(_ string) (err error) {
return errors.New("error") return errors.New("error")
} }
@@ -220,7 +220,7 @@ func Test_buildConfig(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := buildConfig(tt.args.configName, tt.args.kvs); !reflect.DeepEqual(got, tt.want) { if got := buildConfig(tt.args.configName, tt.args.kvs); !reflect.DeepEqual(got, tt.want) {
t.Errorf("buildConfig() = %s, want %s", *got, *tt.want) t.Errorf("buildConfig() = %s, want %s", *got, *tt.want)
} }
@@ -260,7 +260,7 @@ func Test_setConfigWithARN(t *testing.T) {
}, },
arn: "1", arn: "1",
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: false, wantErr: false,
@@ -280,7 +280,7 @@ func Test_setConfigWithARN(t *testing.T) {
}, },
arn: "1", arn: "1",
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return true, nil return true, nil
}, },
wantErr: false, wantErr: false,
@@ -300,7 +300,7 @@ func Test_setConfigWithARN(t *testing.T) {
}, },
arn: "", arn: "",
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: false, wantErr: false,
@@ -320,7 +320,7 @@ func Test_setConfigWithARN(t *testing.T) {
}, },
arn: "", arn: "",
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, errors.New("error") return false, errors.New("error")
}, },
wantErr: true, wantErr: true,
@@ -328,7 +328,7 @@ func Test_setConfigWithARN(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// mock function response from setConfig() // mock function response from setConfig()
minioSetConfigKVMock = tt.mockSetConfig minioSetConfigKVMock = tt.mockSetConfig
restart, err := setConfigWithARNAccountID(tt.args.ctx, tt.args.client, tt.args.configName, tt.args.kvs, tt.args.arn) restart, err := setConfigWithARNAccountID(tt.args.ctx, tt.args.client, tt.args.configName, tt.args.kvs, tt.args.arn)
@@ -361,7 +361,7 @@ func Test_getConfig(t *testing.T) {
}, },
mock: func() { mock: func() {
// mock function response from getConfig() // mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
return []byte(`notify_postgres:_ connection_string="host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable" table=bucketevents`), nil return []byte(`notify_postgres:_ connection_string="host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable" table=bucketevents`), nil
} }
@@ -407,7 +407,7 @@ func Test_getConfig(t *testing.T) {
KeysHelp: configListMock, KeysHelp: configListMock,
} }
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return mockConfigList, nil return mockConfigList, nil
} }
}, },
@@ -435,7 +435,7 @@ func Test_getConfig(t *testing.T) {
}, },
mock: func() { mock: func() {
// mock function response from getConfig() // mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
return []byte(`notify_postgres:_`), nil return []byte(`notify_postgres:_`), nil
} }
@@ -481,7 +481,7 @@ func Test_getConfig(t *testing.T) {
KeysHelp: configListMock, KeysHelp: configListMock,
} }
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return mockConfigList, nil return mockConfigList, nil
} }
}, },
@@ -496,7 +496,7 @@ func Test_getConfig(t *testing.T) {
}, },
mock: func() { mock: func() {
// mock function response from getConfig() // mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
x := make(map[string]string) x := make(map[string]string)
x["x"] = "x" x["x"] = "x"
j, _ := json.Marshal(x) j, _ := json.Marshal(x)
@@ -545,7 +545,7 @@ func Test_getConfig(t *testing.T) {
KeysHelp: configListMock, KeysHelp: configListMock,
} }
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return mockConfigList, nil return mockConfigList, nil
} }
}, },
@@ -560,13 +560,13 @@ func Test_getConfig(t *testing.T) {
}, },
mock: func() { mock: func() {
// mock function response from getConfig() // mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
return nil, errors.New("invalid config") return nil, errors.New("invalid config")
} }
mockConfigList := madmin.Help{} mockConfigList := madmin.Help{}
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return mockConfigList, nil return mockConfigList, nil
} }
}, },
@@ -581,11 +581,11 @@ func Test_getConfig(t *testing.T) {
}, },
mock: func() { mock: func() {
// mock function response from getConfig() // mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
return nil, errors.New("invalid config") return nil, errors.New("invalid config")
} }
// mock function response from listConfig() // mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) { minioHelpConfigKVMock = func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{}, errors.New("no help") return madmin.Help{}, errors.New("no help")
} }
}, },
@@ -595,7 +595,7 @@ func Test_getConfig(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt.mock() tt.mock()
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, err := getConfig(context.Background(), tt.args.client, tt.args.name) got, err := getConfig(context.Background(), tt.args.client, tt.args.name)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("getConfig() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("getConfig() error = %v, wantErr %v", err, tt.wantErr)

View File

@@ -40,7 +40,7 @@ func TestAdminConsoleLog(t *testing.T) {
// Test-1: Serve Console with no errors until Console finishes sending // Test-1: Serve Console with no errors until Console finishes sending
// define mock function behavior for minio server Console // define mock function behavior for minio server Console
minioGetLogsMock = func(ctx context.Context, node string, lineCnt int, logKind string) <-chan madmin.LogInfo { minioGetLogsMock = func(_ context.Context, _ string, _ int, _ string) <-chan madmin.LogInfo {
ch := make(chan madmin.LogInfo) ch := make(chan madmin.LogInfo)
// Only success, start a routine to start reading line by line. // Only success, start a routine to start reading line by line.
go func(ch chan<- madmin.LogInfo) { go func(ch chan<- madmin.LogInfo) {
@@ -58,7 +58,7 @@ func TestAdminConsoleLog(t *testing.T) {
} }
writesCount := 1 writesCount := 1
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, data []byte) error {
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t madmin.LogInfo var t madmin.LogInfo
_ = json.Unmarshal(data, &t) _ = json.Unmarshal(data, &t)
@@ -82,7 +82,7 @@ func TestAdminConsoleLog(t *testing.T) {
} }
// Test-2: if error happens while writing, return error // Test-2: if error happens while writing, return error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return fmt.Errorf("error on write") return fmt.Errorf("error on write")
} }
if err := startConsoleLog(ctx, mockWSConn, adminClient, LogRequest{node: "", logType: "all"}); assert.Error(err) { if err := startConsoleLog(ctx, mockWSConn, adminClient, LogRequest{node: "", logType: "all"}); assert.Error(err) {
@@ -91,7 +91,7 @@ func TestAdminConsoleLog(t *testing.T) {
// Test-3: error happens on GetLogs Minio, Console should stop // Test-3: error happens on GetLogs Minio, Console should stop
// and error shall be returned. // and error shall be returned.
minioGetLogsMock = func(ctx context.Context, node string, lineCnt int, logKind string) <-chan madmin.LogInfo { minioGetLogsMock = func(_ context.Context, _ string, _ int, _ string) <-chan madmin.LogInfo {
ch := make(chan madmin.LogInfo) ch := make(chan madmin.LogInfo)
// Only success, start a routine to start reading line by line. // Only success, start a routine to start reading line by line.
go func(ch chan<- madmin.LogInfo) { go func(ch chan<- madmin.LogInfo) {
@@ -108,7 +108,7 @@ func TestAdminConsoleLog(t *testing.T) {
}(ch) }(ch)
return ch return ch
} }
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return nil return nil
} }
if err := startConsoleLog(ctx, mockWSConn, adminClient, LogRequest{node: "", logType: "all"}); assert.Error(err) { if err := startConsoleLog(ctx, mockWSConn, adminClient, LogRequest{node: "", logType: "all"}); assert.Error(err) {

View File

@@ -130,7 +130,7 @@ func TestGroupInfo(t *testing.T) {
Status: "enabled", Status: "enabled",
} }
// mock function response from updateGroupMembers() // mock function response from updateGroupMembers()
minioGetGroupDescriptionMock = func(group string) (*madmin.GroupDesc, error) { minioGetGroupDescriptionMock = func(_ string) (*madmin.GroupDesc, error) {
return mockResponse, nil return mockResponse, nil
} }
function := "groupInfo()" function := "groupInfo()"
@@ -144,7 +144,7 @@ func TestGroupInfo(t *testing.T) {
assert.Equal("enabled", info.Status) assert.Equal("enabled", info.Status)
// Test-2 : groupInfo() Return error and see that the error is handled correctly and returned // Test-2 : groupInfo() Return error and see that the error is handled correctly and returned
minioGetGroupDescriptionMock = func(group string) (*madmin.GroupDesc, error) { minioGetGroupDescriptionMock = func(_ string) (*madmin.GroupDesc, error) {
return nil, errors.New("error") return nil, errors.New("error")
} }
_, err = groupInfo(ctx, adminClient, groupName) _, err = groupInfo(ctx, adminClient, groupName)
@@ -226,7 +226,7 @@ func TestUpdateGroup(t *testing.T) {
// the function twice but the second time returned an error // the function twice but the second time returned an error
is2ndRunGroupInfo := false is2ndRunGroupInfo := false
// mock function response from updateGroupMembers() // mock function response from updateGroupMembers()
minioGetGroupDescriptionMock = func(group string) (*madmin.GroupDesc, error) { minioGetGroupDescriptionMock = func(_ string) (*madmin.GroupDesc, error) {
if is2ndRunGroupInfo { if is2ndRunGroupInfo {
return mockResponseAfterUpdate, nil return mockResponseAfterUpdate, nil
} }
@@ -236,7 +236,7 @@ func TestUpdateGroup(t *testing.T) {
minioUpdateGroupMembersMock = func(madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(madmin.GroupAddRemove) error {
return nil return nil
} }
minioSetGroupStatusMock = func(group string, status madmin.GroupStatus) error { minioSetGroupStatusMock = func(_ string, _ madmin.GroupStatus) error {
return nil return nil
} }
groupUpdated, err := groupUpdate(ctx, adminClient, groupName, expectedGroupUpdate) groupUpdated, err := groupUpdate(ctx, adminClient, groupName, expectedGroupUpdate)
@@ -258,7 +258,7 @@ func TestSetGroupStatus(t *testing.T) {
defer cancel() defer cancel()
// Test-1: setGroupStatus() update valid disabled status // Test-1: setGroupStatus() update valid disabled status
expectedStatus := "disabled" expectedStatus := "disabled"
minioSetGroupStatusMock = func(group string, status madmin.GroupStatus) error { minioSetGroupStatusMock = func(_ string, _ madmin.GroupStatus) error {
return nil return nil
} }
if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); err != nil { if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); err != nil {
@@ -266,7 +266,7 @@ func TestSetGroupStatus(t *testing.T) {
} }
// Test-2: setGroupStatus() update valid enabled status // Test-2: setGroupStatus() update valid enabled status
expectedStatus = "enabled" expectedStatus = "enabled"
minioSetGroupStatusMock = func(group string, status madmin.GroupStatus) error { minioSetGroupStatusMock = func(_ string, _ madmin.GroupStatus) error {
return nil return nil
} }
if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); err != nil { if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); err != nil {
@@ -274,7 +274,7 @@ func TestSetGroupStatus(t *testing.T) {
} }
// Test-3: setGroupStatus() update invalid status, should send error // Test-3: setGroupStatus() update invalid status, should send error
expectedStatus = "invalid" expectedStatus = "invalid"
minioSetGroupStatusMock = func(group string, status madmin.GroupStatus) error { minioSetGroupStatusMock = func(_ string, _ madmin.GroupStatus) error {
return nil return nil
} }
if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); assert.Error(err) { if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); assert.Error(err) {
@@ -282,7 +282,7 @@ func TestSetGroupStatus(t *testing.T) {
} }
// Test-4: setGroupStatus() handler error correctly // Test-4: setGroupStatus() handler error correctly
expectedStatus = "enabled" expectedStatus = "enabled"
minioSetGroupStatusMock = func(group string, status madmin.GroupStatus) error { minioSetGroupStatusMock = func(_ string, _ madmin.GroupStatus) error {
return errors.New("error") return errors.New("error")
} }
if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); assert.Error(err) { if err := setGroupStatus(ctx, adminClient, groupName, expectedStatus); assert.Error(err) {

View File

@@ -51,7 +51,7 @@ func Test_serverHealthInfo(t *testing.T) {
args: args{ args: args{
deadline: deadlineDuration, deadline: deadlineDuration,
mockMessages: []madmin.HealthInfo{{}, {}}, mockMessages: []madmin.HealthInfo{{}, {}},
wsWriteMock: func(messageType int, data []byte) error { wsWriteMock: func(_ int, data []byte) error {
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t madmin.HealthInfo var t madmin.HealthInfo
@@ -67,7 +67,7 @@ func Test_serverHealthInfo(t *testing.T) {
args: args{ args: args{
deadline: deadlineDuration, deadline: deadlineDuration,
mockMessages: []madmin.HealthInfo{{}}, mockMessages: []madmin.HealthInfo{{}},
wsWriteMock: func(messageType int, data []byte) error { wsWriteMock: func(_ int, data []byte) error {
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t madmin.HealthInfo var t madmin.HealthInfo
@@ -83,7 +83,7 @@ func Test_serverHealthInfo(t *testing.T) {
args: args{ args: args{
deadline: deadlineDuration, deadline: deadlineDuration,
mockMessages: []madmin.HealthInfo{{}}, mockMessages: []madmin.HealthInfo{{}},
wsWriteMock: func(messageType int, data []byte) error { wsWriteMock: func(_ int, data []byte) error {
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t madmin.HealthInfo var t madmin.HealthInfo
@@ -102,7 +102,7 @@ func Test_serverHealthInfo(t *testing.T) {
Error: "error on healthInfo", Error: "error on healthInfo",
}, },
}, },
wsWriteMock: func(messageType int, data []byte) error { wsWriteMock: func(_ int, data []byte) error {
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t madmin.HealthInfo var t madmin.HealthInfo
@@ -115,12 +115,12 @@ func Test_serverHealthInfo(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
// make testReceiver channel // make testReceiver channel
testReceiver = make(chan madmin.HealthInfo, len(tt.args.mockMessages)) testReceiver = make(chan madmin.HealthInfo, len(tt.args.mockMessages))
// mock function same for all tests, changes mockMessages // mock function same for all tests, changes mockMessages
minioServerHealthInfoMock = func(ctx context.Context, healthDataTypes []madmin.HealthDataType, minioServerHealthInfoMock = func(_ context.Context, _ []madmin.HealthDataType,
deadline time.Duration, _ time.Duration,
) (interface{}, string, error) { ) (interface{}, string, error) {
info := tt.args.mockMessages[0] info := tt.args.mockMessages[0]
return info, madmin.HealthInfoVersion, nil return info, madmin.HealthInfoVersion, nil

View File

@@ -46,7 +46,7 @@ type IDPTestSuite struct {
func (suite *IDPTestSuite) SetupSuite() { func (suite *IDPTestSuite) SetupSuite() {
suite.assert = assert.New(suite.T()) suite.assert = assert.New(suite.T())
suite.adminClient = AdminClientMock{} suite.adminClient = AdminClientMock{}
minioServiceRestartMock = func(ctx context.Context) error { minioServiceRestartMock = func(_ context.Context) error {
return nil return nil
} }
} }
@@ -270,7 +270,7 @@ func TestGetEntitiesResult(t *testing.T) {
GroupMappings: groupsMap, GroupMappings: groupsMap,
UserMappings: usersMap, UserMappings: usersMap,
} }
minioGetLDAPPolicyEntitiesMock = func(ctx context.Context, query madmin.PolicyEntitiesQuery) (madmin.PolicyEntitiesResult, error) { minioGetLDAPPolicyEntitiesMock = func(_ context.Context, _ madmin.PolicyEntitiesQuery) (madmin.PolicyEntitiesResult, error) {
return mockResponse, nil return mockResponse, nil
} }
@@ -308,7 +308,7 @@ func TestGetEntitiesResult(t *testing.T) {
} }
// Test-2: getEntitiesResult error is returned from getLDAPPolicyEntities() // Test-2: getEntitiesResult error is returned from getLDAPPolicyEntities()
minioGetLDAPPolicyEntitiesMock = func(ctx context.Context, query madmin.PolicyEntitiesQuery) (madmin.PolicyEntitiesResult, error) { minioGetLDAPPolicyEntitiesMock = func(_ context.Context, _ madmin.PolicyEntitiesQuery) (madmin.PolicyEntitiesResult, error) {
return madmin.PolicyEntitiesResult{}, errors.New("error") return madmin.PolicyEntitiesResult{}, errors.New("error")
} }

View File

@@ -46,7 +46,7 @@ func registerAdminInfoHandlers(api *operations.ConsoleAPI) {
return systemApi.NewAdminInfoOK().WithPayload(infoResp) return systemApi.NewAdminInfoOK().WithPayload(infoResp)
}) })
// return single widget results // return single widget results
api.SystemDashboardWidgetDetailsHandler = systemApi.DashboardWidgetDetailsHandlerFunc(func(params systemApi.DashboardWidgetDetailsParams, session *models.Principal) middleware.Responder { api.SystemDashboardWidgetDetailsHandler = systemApi.DashboardWidgetDetailsHandlerFunc(func(params systemApi.DashboardWidgetDetailsParams, _ *models.Principal) middleware.Responder {
infoResp, err := getAdminInfoWidgetResponse(params) infoResp, err := getAdminInfoWidgetResponse(params)
if err != nil { if err != nil {
return systemApi.NewDashboardWidgetDetailsDefault(err.Code).WithPayload(err.APIError) return systemApi.NewDashboardWidgetDetailsDefault(err.Code).WithPayload(err.APIError)

View File

@@ -46,7 +46,7 @@ type AdminInfoTestSuite struct {
func (suite *AdminInfoTestSuite) SetupSuite() { func (suite *AdminInfoTestSuite) SetupSuite() {
suite.assert = assert.New(suite.T()) suite.assert = assert.New(suite.T())
suite.adminClient = AdminClientMock{} suite.adminClient = AdminClientMock{}
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{ return madmin.InfoMessage{
Servers: []madmin.ServerProperties{{ Servers: []madmin.ServerProperties{{
Disks: []madmin.Disk{{}}, Disks: []madmin.Disk{{}},

View File

@@ -61,7 +61,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -94,7 +94,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, errors.New("error") return false, errors.New("error")
}, },
want: nil, want: nil,
@@ -118,7 +118,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -149,7 +149,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -178,7 +178,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -208,7 +208,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -240,7 +240,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -273,7 +273,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -305,7 +305,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -335,7 +335,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -365,7 +365,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -397,7 +397,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return false, errors.New("invalid config") return false, errors.New("invalid config")
}, },
want: nil, want: nil,
@@ -421,7 +421,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
}, },
}, },
mockSetConfig: func(kv string) (restart bool, err error) { mockSetConfig: func(_ string) (restart bool, err error) {
return true, nil return true, nil
}, },
want: &models.SetNotificationEndpointResponse{ want: &models.SetNotificationEndpointResponse{
@@ -438,7 +438,7 @@ func Test_addNotificationEndpoint(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// mock function response from setConfig() // mock function response from setConfig()
minioSetConfigKVMock = tt.mockSetConfig minioSetConfigKVMock = tt.mockSetConfig
got, err := addNotificationEndpoint(tt.args.ctx, tt.args.client, tt.args.params) got, err := addNotificationEndpoint(tt.args.ctx, tt.args.client, tt.args.params)

View File

@@ -97,11 +97,11 @@ func TestWSRewindObjects(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
mcListMock = func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent { mcListMock = func(_ context.Context, _ mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent) ch := make(chan *mc.ClientContent)
go func() { go func() {
defer close(ch) defer close(ch)
@@ -206,11 +206,11 @@ func TestWSListObjects(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
minioListObjectsMock = func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { minioListObjectsMock = func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
ch := make(chan minio.ObjectInfo) ch := make(chan minio.ObjectInfo)
go func() { go func() {
defer close(ch) defer close(ch)

View File

@@ -83,7 +83,7 @@ func TestRemovePolicy(t *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
// Test-1 : removePolicy() remove an existing policy // Test-1 : removePolicy() remove an existing policy
policyToRemove := "console-policy" policyToRemove := "console-policy"
minioRemovePolicyMock = func(name string) error { minioRemovePolicyMock = func(_ string) error {
return nil return nil
} }
function := "removePolicy()" function := "removePolicy()"
@@ -91,7 +91,7 @@ func TestRemovePolicy(t *testing.T) {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error()) t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
} }
// Test-2 : removePolicy() Return error and see that the error is handled correctly and returned // Test-2 : removePolicy() Return error and see that the error is handled correctly and returned
minioRemovePolicyMock = func(name string) error { minioRemovePolicyMock = func(_ string) error {
return errors.New("error") return errors.New("error")
} }
if err := removePolicy(ctx, adminClient, policyToRemove); funcAssert.Error(err) { if err := removePolicy(ctx, adminClient, policyToRemove); funcAssert.Error(err) {
@@ -106,10 +106,10 @@ func TestAddPolicy(t *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
policyName := "new-policy" policyName := "new-policy"
policyDefinition := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}" policyDefinition := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error { minioAddPolicyMock = func(_ string, _ *iampolicy.Policy) error {
return nil return nil
} }
minioGetPolicyMock = func(name string) (*iampolicy.Policy, error) { minioGetPolicyMock = func(_ string) (*iampolicy.Policy, error) {
policy := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}" policy := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"
iamp, err := iampolicy.ParseConfig(bytes.NewReader([]byte(policy))) iamp, err := iampolicy.ParseConfig(bytes.NewReader([]byte(policy)))
if err != nil { if err != nil {
@@ -138,17 +138,17 @@ func TestAddPolicy(t *testing.T) {
funcAssert.Equal(expectedPolicy, actualPolicy) funcAssert.Equal(expectedPolicy, actualPolicy)
} }
// Test-2 : addPolicy() got an error while adding policy // Test-2 : addPolicy() got an error while adding policy
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error { minioAddPolicyMock = func(_ string, _ *iampolicy.Policy) error {
return errors.New("error") return errors.New("error")
} }
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) { if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) {
funcAssert.Equal("error", err.Error()) funcAssert.Equal("error", err.Error())
} }
// Test-3 : addPolicy() got an error while retrieving policy // Test-3 : addPolicy() got an error while retrieving policy
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error { minioAddPolicyMock = func(_ string, _ *iampolicy.Policy) error {
return nil return nil
} }
minioGetPolicyMock = func(name string) (*iampolicy.Policy, error) { minioGetPolicyMock = func(_ string) (*iampolicy.Policy, error) {
return nil, errors.New("error") return nil, errors.New("error")
} }
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) { if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) {
@@ -164,7 +164,7 @@ func TestSetPolicy(t *testing.T) {
policyName := "readOnly" policyName := "readOnly"
entityName := "alevsk" entityName := "alevsk"
entityObject := models.PolicyEntityUser entityObject := models.PolicyEntityUser
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error { minioSetPolicyMock = func(_, _ string, _ bool) error {
return nil return nil
} }
// Test-1 : SetPolicy() set policy to user // Test-1 : SetPolicy() set policy to user
@@ -181,7 +181,7 @@ func TestSetPolicy(t *testing.T) {
} }
// Test-3 : SetPolicy() set policy to user and get error // Test-3 : SetPolicy() set policy to user and get error
entityObject = models.PolicyEntityUser entityObject = models.PolicyEntityUser
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error { minioSetPolicyMock = func(_, _ string, _ bool) error {
return errors.New("error") return errors.New("error")
} }
if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) { if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
@@ -189,7 +189,7 @@ func TestSetPolicy(t *testing.T) {
} }
// Test-4 : SetPolicy() set policy to group and get error // Test-4 : SetPolicy() set policy to group and get error
entityObject = models.PolicyEntityGroup entityObject = models.PolicyEntityGroup
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error { minioSetPolicyMock = func(_, _ string, _ bool) error {
return errors.New("error") return errors.New("error")
} }
if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) { if err := SetPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
@@ -219,7 +219,7 @@ func Test_SetPolicyMultiple(t *testing.T) {
policyName: "readonly", policyName: "readonly",
users: []models.IamEntity{"user1", "user2"}, users: []models.IamEntity{"user1", "user2"},
groups: []models.IamEntity{"group1", "group2"}, groups: []models.IamEntity{"group1", "group2"},
setPolicyFunc: func(policyName, entityName string, isGroup bool) error { setPolicyFunc: func(_, _ string, _ bool) error {
return nil return nil
}, },
}, },
@@ -231,7 +231,7 @@ func Test_SetPolicyMultiple(t *testing.T) {
policyName: "readonly", policyName: "readonly",
users: []models.IamEntity{"user1", "user2"}, users: []models.IamEntity{"user1", "user2"},
groups: []models.IamEntity{"group1", "group2"}, groups: []models.IamEntity{"group1", "group2"},
setPolicyFunc: func(policyName, entityName string, isGroup bool) error { setPolicyFunc: func(_, _ string, _ bool) error {
return errors.New("error set") return errors.New("error set")
}, },
}, },
@@ -244,7 +244,7 @@ func Test_SetPolicyMultiple(t *testing.T) {
policyName: "readonly", policyName: "readonly",
users: []models.IamEntity{}, users: []models.IamEntity{},
groups: []models.IamEntity{}, groups: []models.IamEntity{},
setPolicyFunc: func(policyName, entityName string, isGroup bool) error { setPolicyFunc: func(_, _ string, _ bool) error {
return nil return nil
}, },
}, },
@@ -252,7 +252,7 @@ func Test_SetPolicyMultiple(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioSetPolicyMock = tt.args.setPolicyFunc minioSetPolicyMock = tt.args.setPolicyFunc
got := setPolicyMultipleEntities(ctx, adminClient, tt.args.policyName, tt.args.users, tt.args.groups) got := setPolicyMultipleEntities(ctx, adminClient, tt.args.policyName, tt.args.users, tt.args.groups)
if !reflect.DeepEqual(got, tt.errorExpected) { if !reflect.DeepEqual(got, tt.errorExpected) {
@@ -373,7 +373,7 @@ func Test_policyMatchesBucket(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := policyMatchesBucket(tt.args.ctx, tt.args.policy, tt.args.bucket); got != tt.want { if got := policyMatchesBucket(tt.args.ctx, tt.args.policy, tt.args.bucket); got != tt.want {
t.Errorf("policyMatchesBucket() = %v, want %v", got, tt.want) t.Errorf("policyMatchesBucket() = %v, want %v", got, tt.want)
} }

View File

@@ -52,7 +52,7 @@ func TestStartProfiling(t *testing.T) {
// Test-1 : startProfiling() Get response from MinIO server with one profiling object without errors // Test-1 : startProfiling() Get response from MinIO server with one profiling object without errors
// mock function response from startProfiling() // mock function response from startProfiling()
minioStartProfiling = func(profiler madmin.ProfilerType) ([]madmin.StartProfilingResult, error) { minioStartProfiling = func(_ madmin.ProfilerType) ([]madmin.StartProfilingResult, error) {
return []madmin.StartProfilingResult{ return []madmin.StartProfilingResult{
{ {
NodeName: "http://127.0.0.1:9000/", NodeName: "http://127.0.0.1:9000/",
@@ -71,7 +71,7 @@ func TestStartProfiling(t *testing.T) {
return &ClosingBuffer{bytes.NewBufferString("In memory string eaeae")}, nil return &ClosingBuffer{bytes.NewBufferString("In memory string eaeae")}, nil
} }
// mock function response from mockConn.writeMessage() // mock function response from mockConn.writeMessage()
connWriteMessageMock = func(messageType int, p []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return nil return nil
} }
err := startProfiling(ctx, mockWSConn, adminClient, testOptions) err := startProfiling(ctx, mockWSConn, adminClient, testOptions)
@@ -82,7 +82,7 @@ func TestStartProfiling(t *testing.T) {
// Test-2 : startProfiling() Correctly handles errors returned by MinIO // Test-2 : startProfiling() Correctly handles errors returned by MinIO
// mock function response from startProfiling() // mock function response from startProfiling()
minioStartProfiling = func(profiler madmin.ProfilerType) ([]madmin.StartProfilingResult, error) { minioStartProfiling = func(_ madmin.ProfilerType) ([]madmin.StartProfilingResult, error) {
return nil, errors.New("error") return nil, errors.New("error")
} }
err = startProfiling(ctx, mockWSConn, adminClient, testOptions) err = startProfiling(ctx, mockWSConn, adminClient, testOptions)

View File

@@ -90,7 +90,7 @@ func registerAdminBucketRemoteHandlers(api *operations.ConsoleAPI) {
}) })
// list external buckets // list external buckets
api.BucketListExternalBucketsHandler = bucketApi.ListExternalBucketsHandlerFunc(func(params bucketApi.ListExternalBucketsParams, session *models.Principal) middleware.Responder { api.BucketListExternalBucketsHandler = bucketApi.ListExternalBucketsHandlerFunc(func(params bucketApi.ListExternalBucketsParams, _ *models.Principal) middleware.Responder {
response, err := listExternalBucketsResponse(params) response, err := listExternalBucketsResponse(params)
if err != nil { if err != nil {
return bucketApi.NewListExternalBucketsDefault(err.Code).WithPayload(err.APIError) return bucketApi.NewListExternalBucketsDefault(err.Code).WithPayload(err.APIError)
@@ -796,7 +796,6 @@ func updateBucketReplicationResponse(session *models.Principal, params bucketApi
params.Body.Tags, params.Body.Tags,
params.Body.Priority, params.Body.Priority,
params.Body.StorageClass) params.Body.StorageClass)
if err != nil { if err != nil {
return ErrorWithContext(ctx, err) return ErrorWithContext(ctx, err)
} }

View File

@@ -299,7 +299,7 @@ func (suite *RemoteBucketsTestSuite) initListExternalBucketsRequest() (params bu
func (suite *RemoteBucketsTestSuite) TestListExternalBucketsWithError() { func (suite *RemoteBucketsTestSuite) TestListExternalBucketsWithError() {
ctx := context.Background() ctx := context.Background()
minioAccountInfoMock = func(ctx context.Context) (madmin.AccountInfo, error) { minioAccountInfoMock = func(_ context.Context) (madmin.AccountInfo, error) {
return madmin.AccountInfo{}, errors.New("error") return madmin.AccountInfo{}, errors.New("error")
} }
res, err := listExternalBuckets(ctx, &suite.adminClient) res, err := listExternalBuckets(ctx, &suite.adminClient)
@@ -309,7 +309,7 @@ func (suite *RemoteBucketsTestSuite) TestListExternalBucketsWithError() {
func (suite *RemoteBucketsTestSuite) TestListExternalBucketsWithoutError() { func (suite *RemoteBucketsTestSuite) TestListExternalBucketsWithoutError() {
ctx := context.Background() ctx := context.Background()
minioAccountInfoMock = func(ctx context.Context) (madmin.AccountInfo, error) { minioAccountInfoMock = func(_ context.Context) (madmin.AccountInfo, error) {
return madmin.AccountInfo{ return madmin.AccountInfo{
Buckets: []madmin.BucketAccessInfo{}, Buckets: []madmin.BucketAccessInfo{},
}, nil }, nil

View File

@@ -32,10 +32,10 @@ func TestServiceRestart(t *testing.T) {
function := "serviceRestart()" function := "serviceRestart()"
// Test-1 : serviceRestart() restart services no errors // Test-1 : serviceRestart() restart services no errors
// mock function response from listGroups() // mock function response from listGroups()
minioServiceRestartMock = func(ctx context.Context) error { minioServiceRestartMock = func(_ context.Context) error {
return nil return nil
} }
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{}, nil return madmin.InfoMessage{}, nil
} }
if err := serviceRestart(ctx, adminClient); err != nil { if err := serviceRestart(ctx, adminClient); err != nil {
@@ -44,10 +44,10 @@ func TestServiceRestart(t *testing.T) {
// Test-2 : serviceRestart() returns errors on client.serviceRestart call // Test-2 : serviceRestart() returns errors on client.serviceRestart call
// and see that the errors is handled correctly and returned // and see that the errors is handled correctly and returned
minioServiceRestartMock = func(ctx context.Context) error { minioServiceRestartMock = func(_ context.Context) error {
return errors.New("error") return errors.New("error")
} }
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{}, nil return madmin.InfoMessage{}, nil
} }
if err := serviceRestart(ctx, adminClient); assert.Error(err) { if err := serviceRestart(ctx, adminClient); assert.Error(err) {
@@ -56,10 +56,10 @@ func TestServiceRestart(t *testing.T) {
// Test-3 : serviceRestart() returns errors on client.serverInfo() call // Test-3 : serviceRestart() returns errors on client.serverInfo() call
// and see that the errors is handled correctly and returned // and see that the errors is handled correctly and returned
minioServiceRestartMock = func(ctx context.Context) error { minioServiceRestartMock = func(_ context.Context) error {
return nil return nil
} }
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{}, errors.New("error on server info") return madmin.InfoMessage{}, errors.New("error on server info")
} }
if err := serviceRestart(ctx, adminClient); assert.Error(err) { if err := serviceRestart(ctx, adminClient); assert.Error(err) {

View File

@@ -72,7 +72,7 @@ func TestGetSiteReplicationInfo(t *testing.T) {
ServiceAccountAccessKey: "test-key", ServiceAccountAccessKey: "test-key",
} }
getSiteReplicationInfo = func(ctx context.Context) (info *madmin.SiteReplicationInfo, err error) { getSiteReplicationInfo = func(_ context.Context) (info *madmin.SiteReplicationInfo, err error) {
return &retValueMock, nil return &retValueMock, nil
} }
@@ -104,7 +104,7 @@ func TestAddSiteReplicationInfo(t *testing.T) {
InitialSyncErrorMessage: "", InitialSyncErrorMessage: "",
} }
addSiteReplicationInfo = func(ctx context.Context, sites []madmin.PeerSite) (res *madmin.ReplicateAddStatus, err error) { addSiteReplicationInfo = func(_ context.Context, _ []madmin.PeerSite) (res *madmin.ReplicateAddStatus, err error) {
return retValueMock, nil return retValueMock, nil
} }
@@ -149,7 +149,7 @@ func TestEditSiteReplicationInfo(t *testing.T) {
ErrDetail: "", ErrDetail: "",
} }
editSiteReplicationInfo = func(ctx context.Context, site madmin.PeerInfo) (res *madmin.ReplicateEditStatus, err error) { editSiteReplicationInfo = func(_ context.Context, _ madmin.PeerInfo) (res *madmin.ReplicateEditStatus, err error) {
return retValueMock, nil return retValueMock, nil
} }
@@ -183,7 +183,7 @@ func TestDeleteSiteReplicationInfo(t *testing.T) {
ErrDetail: "", ErrDetail: "",
} }
deleteSiteReplicationInfoMock = func(ctx context.Context, removeReq madmin.SRRemoveReq) (res *madmin.ReplicateRemoveStatus, err error) { deleteSiteReplicationInfoMock = func(_ context.Context, _ madmin.SRRemoveReq) (res *madmin.ReplicateRemoveStatus, err error) {
return retValueMock, nil return retValueMock, nil
} }
@@ -236,7 +236,7 @@ func TestSiteReplicationStatus(t *testing.T) {
GroupStats: nil, GroupStats: nil,
} }
getSiteReplicationStatus = func(ctx context.Context, params madmin.SRStatusOptions) (info *madmin.SRStatusInfo, err error) { getSiteReplicationStatus = func(_ context.Context, _ madmin.SRStatusOptions) (info *madmin.SRStatusInfo, err error) {
return &retValueMock, nil return &retValueMock, nil
} }

View File

@@ -44,10 +44,10 @@ type AdminSubnetTestSuite struct {
func (suite *AdminSubnetTestSuite) SetupSuite() { func (suite *AdminSubnetTestSuite) SetupSuite() {
suite.assert = assert.New(suite.T()) suite.assert = assert.New(suite.T())
suite.adminClient = AdminClientMock{} suite.adminClient = AdminClientMock{}
minioGetConfigKVMock = func(key string) ([]byte, error) { minioGetConfigKVMock = func(_ string) ([]byte, error) {
return []byte("subnet license=mock api_key=mock proxy=http://mock.com"), nil return []byte("subnet license=mock api_key=mock proxy=http://mock.com"), nil
} }
MinioServerInfoMock = func(ctx context.Context) (madmin.InfoMessage, error) { MinioServerInfoMock = func(_ context.Context) (madmin.InfoMessage, error) {
return madmin.InfoMessage{Servers: []madmin.ServerProperties{{}}}, nil return madmin.InfoMessage{Servers: []madmin.ServerProperties{{}}}, nil
} }
} }

View File

@@ -89,11 +89,11 @@ func TestGetTiers(t *testing.T) {
}, },
} }
minioListTiersMock = func(ctx context.Context) ([]*madmin.TierConfig, error) { minioListTiersMock = func(_ context.Context) ([]*madmin.TierConfig, error) {
return returnListMock, nil return returnListMock, nil
} }
minioTierStatsMock = func(ctx context.Context) ([]madmin.TierInfo, error) { minioTierStatsMock = func(_ context.Context) ([]madmin.TierInfo, error) {
return returnStatsMock, nil return returnStatsMock, nil
} }
@@ -138,7 +138,7 @@ func TestGetTiers(t *testing.T) {
// Test-2 : getBucketLifecycle() list is empty // Test-2 : getBucketLifecycle() list is empty
returnListMockT2 := []*madmin.TierConfig{} returnListMockT2 := []*madmin.TierConfig{}
minioListTiersMock = func(ctx context.Context) ([]*madmin.TierConfig, error) { minioListTiersMock = func(_ context.Context) ([]*madmin.TierConfig, error) {
return returnListMockT2, nil return returnListMockT2, nil
} }
@@ -161,7 +161,7 @@ func TestAddTier(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
// Test-1: addTier() add new Tier // Test-1: addTier() add new Tier
minioAddTiersMock = func(ctx context.Context, tier *madmin.TierConfig) error { minioAddTiersMock = func(_ context.Context, _ *madmin.TierConfig) error {
return nil return nil
} }
@@ -185,7 +185,7 @@ func TestAddTier(t *testing.T) {
assert.Equal(nil, err, fmt.Sprintf("Failed on %s: Error returned", function)) assert.Equal(nil, err, fmt.Sprintf("Failed on %s: Error returned", function))
// Test-2: addTier() error adding Tier // Test-2: addTier() error adding Tier
minioAddTiersMock = func(ctx context.Context, tier *madmin.TierConfig) error { minioAddTiersMock = func(_ context.Context, _ *madmin.TierConfig) error {
return errors.New("error setting new tier") return errors.New("error setting new tier")
} }
@@ -203,7 +203,7 @@ func TestUpdateTierCreds(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
// Test-1: editTierCredentials() update Tier configuration // Test-1: editTierCredentials() update Tier configuration
minioEditTiersMock = func(ctx context.Context, tierName string, creds madmin.TierCreds) error { minioEditTiersMock = func(_ context.Context, _ string, _ madmin.TierCreds) error {
return nil return nil
} }
@@ -220,7 +220,7 @@ func TestUpdateTierCreds(t *testing.T) {
assert.Equal(nil, err, fmt.Sprintf("Failed on %s: Error returned", function)) assert.Equal(nil, err, fmt.Sprintf("Failed on %s: Error returned", function))
// Test-2: editTierCredentials() update Tier configuration failure // Test-2: editTierCredentials() update Tier configuration failure
minioEditTiersMock = func(ctx context.Context, tierName string, creds madmin.TierCreds) error { minioEditTiersMock = func(_ context.Context, _ string, _ madmin.TierCreds) error {
return errors.New("error message") return errors.New("error message")
} }

View File

@@ -41,7 +41,7 @@ func TestAdminTrace(t *testing.T) {
// Test-1: Serve Trace with no errors until trace finishes sending // Test-1: Serve Trace with no errors until trace finishes sending
// define mock function behavior for minio server Trace // define mock function behavior for minio server Trace
minioServiceTraceMock = func(ctx context.Context, threshold int64, s3, internal, storage, os, errTrace bool) <-chan madmin.ServiceTraceInfo { minioServiceTraceMock = func(_ context.Context, _ int64, _, _, _, _, _ bool) <-chan madmin.ServiceTraceInfo {
ch := make(chan madmin.ServiceTraceInfo) ch := make(chan madmin.ServiceTraceInfo)
// Only success, start a routine to start reading line by line. // Only success, start a routine to start reading line by line.
go func(ch chan<- madmin.ServiceTraceInfo) { go func(ch chan<- madmin.ServiceTraceInfo) {
@@ -59,7 +59,7 @@ func TestAdminTrace(t *testing.T) {
} }
writesCount := 1 writesCount := 1
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, data []byte) error {
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t shortTraceMsg var t shortTraceMsg
_ = json.Unmarshal(data, &t) _ = json.Unmarshal(data, &t)
@@ -84,7 +84,7 @@ func TestAdminTrace(t *testing.T) {
} }
// Test-2: if error happens while writing, return error // Test-2: if error happens while writing, return error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return fmt.Errorf("error on write") return fmt.Errorf("error on write")
} }
if err := startTraceInfo(ctx, mockWSConn, adminClient, TraceRequest{}); assert.Error(err) { if err := startTraceInfo(ctx, mockWSConn, adminClient, TraceRequest{}); assert.Error(err) {
@@ -93,7 +93,7 @@ func TestAdminTrace(t *testing.T) {
// Test-3: error happens on serviceTrace Minio, trace should stop // Test-3: error happens on serviceTrace Minio, trace should stop
// and error shall be returned. // and error shall be returned.
minioServiceTraceMock = func(ctx context.Context, threshold int64, s3, internal, storage, os, errTrace bool) <-chan madmin.ServiceTraceInfo { minioServiceTraceMock = func(_ context.Context, _ int64, _, _, _, _, _ bool) <-chan madmin.ServiceTraceInfo {
ch := make(chan madmin.ServiceTraceInfo) ch := make(chan madmin.ServiceTraceInfo)
// Only success, start a routine to start reading line by line. // Only success, start a routine to start reading line by line.
go func(ch chan<- madmin.ServiceTraceInfo) { go func(ch chan<- madmin.ServiceTraceInfo) {
@@ -110,7 +110,7 @@ func TestAdminTrace(t *testing.T) {
}(ch) }(ch)
return ch return ch
} }
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return nil return nil
} }
if err := startTraceInfo(ctx, mockWSConn, adminClient, TraceRequest{}); assert.Error(err) { if err := startTraceInfo(ctx, mockWSConn, adminClient, TraceRequest{}); assert.Error(err) {

View File

@@ -102,15 +102,15 @@ func TestAddUser(t *testing.T) {
} }
// mock function response from addUser() return no error // mock function response from addUser() return no error
minioAddUserMock = func(accessKey, secretKey string) error { minioAddUserMock = func(_, _ string) error {
return nil return nil
} }
minioGetUserInfoMock = func(accessKey string) (madmin.UserInfo, error) { minioGetUserInfoMock = func(_ string) (madmin.UserInfo, error) {
return *mockResponse, nil return *mockResponse, nil
} }
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return nil return nil
} }
// Test-1: Add a user // Test-1: Add a user
@@ -135,7 +135,7 @@ func TestAddUser(t *testing.T) {
accessKey = "AB" accessKey = "AB"
secretKey = "ABCDEFGHIABCDEFGHI" secretKey = "ABCDEFGHIABCDEFGHI"
// mock function response from addUser() return no error // mock function response from addUser() return no error
minioAddUserMock = func(accessKey, secretKey string) error { minioAddUserMock = func(_, _ string) error {
return errors.New("error") return errors.New("error")
} }
@@ -150,7 +150,7 @@ func TestAddUser(t *testing.T) {
} }
// Test-4: add groups function returns an error // Test-4: add groups function returns an error
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return errors.New("error") return errors.New("error")
} }
@@ -175,7 +175,7 @@ func TestRemoveUser(t *testing.T) {
// Test-1: removeUser() delete a user // Test-1: removeUser() delete a user
// mock function response from removeUser(accessKey) // mock function response from removeUser(accessKey)
minioRemoveUserMock = func(accessKey string) error { minioRemoveUserMock = func(_ string) error {
return nil return nil
} }
@@ -185,7 +185,7 @@ func TestRemoveUser(t *testing.T) {
// Test-2: removeUser() make sure errors are handled correctly when error on DeleteUser() // Test-2: removeUser() make sure errors are handled correctly when error on DeleteUser()
// mock function response from removeUser(accessKey) // mock function response from removeUser(accessKey)
minioRemoveUserMock = func(accessKey string) error { minioRemoveUserMock = func(_ string) error {
return errors.New("error") return errors.New("error")
} }
@@ -220,11 +220,11 @@ func TestUserGroups(t *testing.T) {
// Test-1: updateUserGroups() updates the groups for a user // Test-1: updateUserGroups() updates the groups for a user
// mock function response from updateUserGroups(accessKey, groupsToAssign) // mock function response from updateUserGroups(accessKey, groupsToAssign)
minioGetUserInfoMock = func(accessKey string) (madmin.UserInfo, error) { minioGetUserInfoMock = func(_ string) (madmin.UserInfo, error) {
return *mockResponse, nil return *mockResponse, nil
} }
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return nil return nil
} }
@@ -235,7 +235,7 @@ func TestUserGroups(t *testing.T) {
// Test-2: updateUserGroups() make sure errors are handled correctly when error on UpdateGroupMembersMock() // Test-2: updateUserGroups() make sure errors are handled correctly when error on UpdateGroupMembersMock()
// mock function response from removeUser(accessKey) // mock function response from removeUser(accessKey)
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return errors.New("error") return errors.New("error")
} }
@@ -244,11 +244,11 @@ func TestUserGroups(t *testing.T) {
} }
// Test-3: updateUserGroups() make sure we return the correct error when getUserInfo returns error // Test-3: updateUserGroups() make sure we return the correct error when getUserInfo returns error
minioGetUserInfoMock = func(accessKey string) (madmin.UserInfo, error) { minioGetUserInfoMock = func(_ string) (madmin.UserInfo, error) {
return *mockEmptyResponse, errors.New("error getting user ") return *mockEmptyResponse, errors.New("error getting user ")
} }
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return nil return nil
} }
@@ -279,7 +279,7 @@ func TestGetUserInfo(t *testing.T) {
} }
// mock function response from getUserInfo() // mock function response from getUserInfo()
minioGetUserInfoMock = func(username string) (madmin.UserInfo, error) { minioGetUserInfoMock = func(_ string) (madmin.UserInfo, error) {
return *mockResponse, nil return *mockResponse, nil
} }
function := "getUserInfo()" function := "getUserInfo()"
@@ -294,7 +294,7 @@ func TestGetUserInfo(t *testing.T) {
assert.Equal(mockResponse.Status, info.Status) assert.Equal(mockResponse.Status, info.Status)
// Test-2 : getUserInfo() Return error and see that the error is handled correctly and returned // Test-2 : getUserInfo() Return error and see that the error is handled correctly and returned
minioGetUserInfoMock = func(username string) (madmin.UserInfo, error) { minioGetUserInfoMock = func(_ string) (madmin.UserInfo, error) {
return *emptyMockResponse, errors.New("error") return *emptyMockResponse, errors.New("error")
} }
_, err = getUserInfo(ctx, adminClient, userName) _, err = getUserInfo(ctx, adminClient, userName)
@@ -313,7 +313,7 @@ func TestSetUserStatus(t *testing.T) {
// Test-1: setUserStatus() update valid disabled status // Test-1: setUserStatus() update valid disabled status
expectedStatus := "disabled" expectedStatus := "disabled"
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error { minioSetUserStatusMock = func(_ string, _ madmin.AccountStatus) error {
return nil return nil
} }
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil { if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil {
@@ -321,7 +321,7 @@ func TestSetUserStatus(t *testing.T) {
} }
// Test-2: setUserStatus() update valid enabled status // Test-2: setUserStatus() update valid enabled status
expectedStatus = "enabled" expectedStatus = "enabled"
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error { minioSetUserStatusMock = func(_ string, _ madmin.AccountStatus) error {
return nil return nil
} }
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil { if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil {
@@ -329,7 +329,7 @@ func TestSetUserStatus(t *testing.T) {
} }
// Test-3: setUserStatus() update invalid status, should send error // Test-3: setUserStatus() update invalid status, should send error
expectedStatus = "invalid" expectedStatus = "invalid"
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error { minioSetUserStatusMock = func(_ string, _ madmin.AccountStatus) error {
return nil return nil
} }
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) { if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) {
@@ -337,7 +337,7 @@ func TestSetUserStatus(t *testing.T) {
} }
// Test-4: setUserStatus() handler error correctly // Test-4: setUserStatus() handler error correctly
expectedStatus = "enabled" expectedStatus = "enabled"
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error { minioSetUserStatusMock = func(_ string, _ madmin.AccountStatus) error {
return errors.New("error") return errors.New("error")
} }
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) { if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) {
@@ -358,7 +358,7 @@ func TestUserGroupsBulk(t *testing.T) {
// Test-1: addUsersListToGroups() updates the groups for a users list // Test-1: addUsersListToGroups() updates the groups for a users list
// mock function response from updateUserGroups(accessKey, groupsToAssign) // mock function response from updateUserGroups(accessKey, groupsToAssign)
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return nil return nil
} }
@@ -368,7 +368,7 @@ func TestUserGroupsBulk(t *testing.T) {
// Test-2: addUsersListToGroups() make sure errors are handled correctly when error on updateGroupMembers() // Test-2: addUsersListToGroups() make sure errors are handled correctly when error on updateGroupMembers()
// mock function response from removeUser(accessKey) // mock function response from removeUser(accessKey)
minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { minioUpdateGroupMembersMock = func(_ madmin.GroupAddRemove) error {
return errors.New("error") return errors.New("error")
} }
@@ -527,7 +527,7 @@ func TestListUsersWithAccessToBucket(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, _ := listUsersWithAccessToBucket(ctx, adminClient, tt.args.bucket) got, _ := listUsersWithAccessToBucket(ctx, adminClient, tt.args.bucket)
assert.Equal(got, tt.want) assert.Equal(got, tt.want)
}) })

View File

@@ -76,7 +76,7 @@ func Test_computeObjectURLWithoutEncode(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, err := computeObjectURLWithoutEncode(tt.args.bucketName, tt.args.prefix) got, err := computeObjectURLWithoutEncode(tt.args.bucketName, tt.args.prefix)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("computeObjectURLWithoutEncode() errors = %v, wantErr %v", err, tt.wantErr) t.Errorf("computeObjectURLWithoutEncode() errors = %v, wantErr %v", err, tt.wantErr)

View File

@@ -54,7 +54,7 @@ func TestGetPort(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsolePort, tt.args.env) os.Setenv(ConsolePort, tt.args.env)
assert.Equalf(t, tt.want, GetPort(), "GetPort()") assert.Equalf(t, tt.want, GetPort(), "GetPort()")
os.Unsetenv(ConsolePort) os.Unsetenv(ConsolePort)
@@ -87,7 +87,7 @@ func TestGetTLSPort(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleTLSPort, tt.args.env) os.Setenv(ConsoleTLSPort, tt.args.env)
assert.Equalf(t, tt.want, GetTLSPort(), "GetTLSPort()") assert.Equalf(t, tt.want, GetTLSPort(), "GetTLSPort()")
os.Unsetenv(ConsoleTLSPort) os.Unsetenv(ConsoleTLSPort)
@@ -120,7 +120,7 @@ func TestGetSecureAllowedHosts(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleSecureAllowedHosts, tt.args.env) os.Setenv(ConsoleSecureAllowedHosts, tt.args.env)
assert.Equalf(t, tt.want, GetSecureAllowedHosts(), "GetSecureAllowedHosts()") assert.Equalf(t, tt.want, GetSecureAllowedHosts(), "GetSecureAllowedHosts()")
os.Unsetenv(ConsoleSecureAllowedHosts) os.Unsetenv(ConsoleSecureAllowedHosts)
@@ -153,7 +153,7 @@ func TestGetSecureHostsProxyHeaders(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleSecureHostsProxyHeaders, tt.args.env) os.Setenv(ConsoleSecureHostsProxyHeaders, tt.args.env)
assert.Equalf(t, tt.want, GetSecureHostsProxyHeaders(), "GetSecureHostsProxyHeaders()") assert.Equalf(t, tt.want, GetSecureHostsProxyHeaders(), "GetSecureHostsProxyHeaders()")
os.Unsetenv(ConsoleSecureHostsProxyHeaders) os.Unsetenv(ConsoleSecureHostsProxyHeaders)
@@ -186,7 +186,7 @@ func TestGetSecureSTSSeconds(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleSecureSTSSeconds, tt.args.env) os.Setenv(ConsoleSecureSTSSeconds, tt.args.env)
assert.Equalf(t, tt.want, GetSecureSTSSeconds(), "GetSecureSTSSeconds()") assert.Equalf(t, tt.want, GetSecureSTSSeconds(), "GetSecureSTSSeconds()")
os.Unsetenv(ConsoleSecureSTSSeconds) os.Unsetenv(ConsoleSecureSTSSeconds)
@@ -219,7 +219,7 @@ func Test_getLogSearchAPIToken(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleLogQueryAuthToken, tt.args.env) os.Setenv(ConsoleLogQueryAuthToken, tt.args.env)
assert.Equalf(t, tt.want, getLogSearchAPIToken(), "getLogSearchAPIToken()") assert.Equalf(t, tt.want, getLogSearchAPIToken(), "getLogSearchAPIToken()")
os.Setenv(ConsoleLogQueryAuthToken, tt.args.env) os.Setenv(ConsoleLogQueryAuthToken, tt.args.env)
@@ -252,7 +252,7 @@ func Test_getPrometheusURL(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(PrometheusURL, tt.args.env) os.Setenv(PrometheusURL, tt.args.env)
assert.Equalf(t, tt.want, getPrometheusURL(), "getPrometheusURL()") assert.Equalf(t, tt.want, getPrometheusURL(), "getPrometheusURL()")
os.Setenv(PrometheusURL, tt.args.env) os.Setenv(PrometheusURL, tt.args.env)
@@ -285,7 +285,7 @@ func Test_getPrometheusJobID(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(PrometheusJobID, tt.args.env) os.Setenv(PrometheusJobID, tt.args.env)
assert.Equalf(t, tt.want, getPrometheusJobID(), "getPrometheusJobID()") assert.Equalf(t, tt.want, getPrometheusJobID(), "getPrometheusJobID()")
os.Setenv(PrometheusJobID, tt.args.env) os.Setenv(PrometheusJobID, tt.args.env)
@@ -318,7 +318,7 @@ func Test_getMaxConcurrentUploadsLimit(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleMaxConcurrentUploads, tt.args.env) os.Setenv(ConsoleMaxConcurrentUploads, tt.args.env)
assert.Equalf(t, tt.want, getMaxConcurrentUploadsLimit(), "getMaxConcurrentUploadsLimit()") assert.Equalf(t, tt.want, getMaxConcurrentUploadsLimit(), "getMaxConcurrentUploadsLimit()")
os.Unsetenv(ConsoleMaxConcurrentUploads) os.Unsetenv(ConsoleMaxConcurrentUploads)
@@ -351,7 +351,7 @@ func Test_getMaxConcurrentDownloadsLimit(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleMaxConcurrentDownloads, tt.args.env) os.Setenv(ConsoleMaxConcurrentDownloads, tt.args.env)
assert.Equalf(t, tt.want, getMaxConcurrentDownloadsLimit(), "getMaxConcurrentDownloadsLimit()") assert.Equalf(t, tt.want, getMaxConcurrentDownloadsLimit(), "getMaxConcurrentDownloadsLimit()")
os.Unsetenv(ConsoleMaxConcurrentDownloads) os.Unsetenv(ConsoleMaxConcurrentDownloads)
@@ -384,7 +384,7 @@ func Test_getConsoleDevMode(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
os.Setenv(ConsoleDevMode, tt.args.env) os.Setenv(ConsoleDevMode, tt.args.env)
assert.Equalf(t, tt.want, getConsoleDevMode(), "getConsoleDevMode()") assert.Equalf(t, tt.want, getConsoleDevMode(), "getConsoleDevMode()")
os.Unsetenv(ConsoleDevMode) os.Unsetenv(ConsoleDevMode)

View File

@@ -82,7 +82,7 @@ func configureFlags(api *operations.ConsoleAPI) {
func configureAPI(api *operations.ConsoleAPI) http.Handler { func configureAPI(api *operations.ConsoleAPI) http.Handler {
// Applies when the "x-token" header is set // Applies when the "x-token" header is set
api.KeyAuth = func(token string, scopes []string) (*models.Principal, error) { api.KeyAuth = func(token string, _ []string) (*models.Principal, error) {
// we are validating the session token by decrypting the claims inside, if the operation succeed that means the jwt // we are validating the session token by decrypting the claims inside, if the operation succeed that means the jwt
// was generated and signed by us in the first place // was generated and signed by us in the first place
if token == "Anonymous" { if token == "Anonymous" {
@@ -103,7 +103,7 @@ func configureAPI(api *operations.ConsoleAPI) http.Handler {
CustomStyleOb: claims.CustomStyleOB, CustomStyleOb: claims.CustomStyleOB,
}, nil }, nil
} }
api.AnonymousAuth = func(s string) (*models.Principal, error) { api.AnonymousAuth = func(_ string) (*models.Principal, error) {
return &models.Principal{}, nil return &models.Principal{}, nil
} }

View File

@@ -70,7 +70,7 @@ func Test_parseSubPath(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, parseSubPath(tt.args.v), "parseSubPath(%v)", tt.args.v) assert.Equalf(t, tt.want, parseSubPath(tt.args.v), "parseSubPath(%v)", tt.args.v)
}) })
} }
@@ -115,7 +115,7 @@ func Test_getSubPath(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
t.Setenv(SubPath, tt.args.envValue) t.Setenv(SubPath, tt.args.envValue)
defer os.Unsetenv(SubPath) defer os.Unsetenv(SubPath)
subPathOnce = sync.Once{} subPathOnce = sync.Once{}

View File

@@ -122,7 +122,7 @@ func TestError(t *testing.T) {
}) })
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got := Error(tt.args.err...) got := Error(tt.args.err...)
assert.Equalf(t, tt.want.Code, got.Code, "Error(%v) Got (%v)", tt.want.Code, got.Code) assert.Equalf(t, tt.want.Code, got.Code, "Error(%v) Got (%v)", tt.want.Code, got.Code)
assert.Equalf(t, tt.want.APIError.DetailedMessage, got.APIError.DetailedMessage, "Error(%s) Got (%s)", tt.want.APIError.DetailedMessage, got.APIError.DetailedMessage) assert.Equalf(t, tt.want.APIError.DetailedMessage, got.APIError.DetailedMessage, "Error(%s) Got (%s)", tt.want.APIError.DetailedMessage, got.APIError.DetailedMessage)
@@ -152,7 +152,7 @@ func TestErrorWithContext(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, ErrorWithContext(tt.args.ctx, tt.args.err...), "ErrorWithContext(%v, %v)", tt.args.ctx, tt.args.err) assert.Equalf(t, tt.want, ErrorWithContext(tt.args.ctx, tt.args.err...), "ErrorWithContext(%v, %v)", tt.args.ctx, tt.args.err)
}) })
} }

View File

@@ -85,7 +85,7 @@ func TestContext_Load(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
c := &Context{} c := &Context{}
fs := flag.NewFlagSet("flags", flag.ContinueOnError) fs := flag.NewFlagSet("flags", flag.ContinueOnError)

View File

@@ -94,7 +94,7 @@ func TestReplacePolicyVariables(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got := ReplacePolicyVariables(tt.args.claims, tt.args.accountInfo) got := ReplacePolicyVariables(tt.args.claims, tt.args.accountInfo)
policy, err := minioIAMPolicy.ParseConfig(bytes.NewReader(got)) policy, err := minioIAMPolicy.ParseConfig(bytes.NewReader(got))
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {

View File

@@ -41,7 +41,7 @@ func TestAddServiceAccount(t *testing.T) {
AccessKey: "minio", AccessKey: "minio",
SecretKey: "minio123", SecretKey: "minio123",
} }
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy, user string, accessKey string, secretKey string, name string, description string, expiry *time.Time, comment string) (madmin.Credentials, error) { minioAddServiceAccountMock = func(_ context.Context, _ *iampolicy.Policy, _ string, _ string, _ string, _ string, _ string, _ *time.Time, _ string) (madmin.Credentials, error) {
return mockResponse, nil return mockResponse, nil
} }
saCreds, err := createServiceAccount(ctx, client, policyDefinition, "", "", nil, "") saCreds, err := createServiceAccount(ctx, client, policyDefinition, "", "", nil, "")
@@ -57,7 +57,7 @@ func TestAddServiceAccount(t *testing.T) {
AccessKey: "minio", AccessKey: "minio",
SecretKey: "minio123", SecretKey: "minio123",
} }
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy, user string, accessKey string, secretKey string, name string, description string, expiry *time.Time, comment string) (madmin.Credentials, error) { minioAddServiceAccountMock = func(_ context.Context, _ *iampolicy.Policy, _ string, _ string, _ string, _ string, _ string, _ *time.Time, _ string) (madmin.Credentials, error) {
return mockResponse, nil return mockResponse, nil
} }
_, err = createServiceAccount(ctx, client, policyDefinition, "", "", nil, "") _, err = createServiceAccount(ctx, client, policyDefinition, "", "", nil, "")
@@ -69,7 +69,7 @@ func TestAddServiceAccount(t *testing.T) {
AccessKey: "minio", AccessKey: "minio",
SecretKey: "minio123", SecretKey: "minio123",
} }
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy, user string, accessKey string, secretKey string, name string, description string, expiry *time.Time, comment string) (madmin.Credentials, error) { minioAddServiceAccountMock = func(_ context.Context, _ *iampolicy.Policy, _ string, _ string, _ string, _ string, _ string, _ *time.Time, _ string) (madmin.Credentials, error) {
return madmin.Credentials{}, errors.New("error") return madmin.Credentials{}, errors.New("error")
} }
_, err = createServiceAccount(ctx, client, policyDefinition, "", "", nil, "") _, err = createServiceAccount(ctx, client, policyDefinition, "", "", nil, "")
@@ -96,7 +96,7 @@ func TestListServiceAccounts(t *testing.T) {
}, },
}, },
} }
minioListServiceAccountsMock = func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error) { minioListServiceAccountsMock = func(_ context.Context, _ string) (madmin.ListServiceAccountsResp, error) {
return mockResponse, nil return mockResponse, nil
} }
@@ -109,7 +109,7 @@ func TestListServiceAccounts(t *testing.T) {
Description: "", Description: "",
Expiration: nil, Expiration: nil,
} }
minioInfoServiceAccountMock = func(ctx context.Context, serviceAccount string) (madmin.InfoServiceAccountResp, error) { minioInfoServiceAccountMock = func(_ context.Context, _ string) (madmin.InfoServiceAccountResp, error) {
return mockInfoResp, nil return mockInfoResp, nil
} }
_, err := getUserServiceAccounts(ctx, client, "") _, err := getUserServiceAccounts(ctx, client, "")
@@ -118,7 +118,7 @@ func TestListServiceAccounts(t *testing.T) {
} }
// Test-2: getUserServiceAccounts returns an error, handle it properly // Test-2: getUserServiceAccounts returns an error, handle it properly
minioListServiceAccountsMock = func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error) { minioListServiceAccountsMock = func(_ context.Context, _ string) (madmin.ListServiceAccountsResp, error) {
return madmin.ListServiceAccountsResp{}, errors.New("error") return madmin.ListServiceAccountsResp{}, errors.New("error")
} }
_, err = getUserServiceAccounts(ctx, client, "") _, err = getUserServiceAccounts(ctx, client, "")
@@ -137,7 +137,7 @@ func TestDeleteServiceAccount(t *testing.T) {
// Test-1: deleteServiceAccount receive a service account to delete // Test-1: deleteServiceAccount receive a service account to delete
testServiceAccount := "accesskeytest" testServiceAccount := "accesskeytest"
minioDeleteServiceAccountMock = func(ctx context.Context, serviceAccount string) error { minioDeleteServiceAccountMock = func(_ context.Context, _ string) error {
return nil return nil
} }
if err := deleteServiceAccount(ctx, client, testServiceAccount); err != nil { if err := deleteServiceAccount(ctx, client, testServiceAccount); err != nil {
@@ -145,7 +145,7 @@ func TestDeleteServiceAccount(t *testing.T) {
} }
// Test-2: if an invalid policy is assigned to the service account, this will raise an error // Test-2: if an invalid policy is assigned to the service account, this will raise an error
minioDeleteServiceAccountMock = func(ctx context.Context, serviceAccount string) error { minioDeleteServiceAccountMock = func(_ context.Context, _ string) error {
return errors.New("error") return errors.New("error")
} }
@@ -181,7 +181,7 @@ func TestGetServiceAccountDetails(t *testing.T) {
}`, }`,
} }
minioInfoServiceAccountMock = func(ctx context.Context, user string) (madmin.InfoServiceAccountResp, error) { minioInfoServiceAccountMock = func(_ context.Context, _ string) (madmin.InfoServiceAccountResp, error) {
return mockResponse, nil return mockResponse, nil
} }
serviceAccount, err := getServiceAccountDetails(ctx, client, "") serviceAccount, err := getServiceAccountDetails(ctx, client, "")
@@ -191,7 +191,7 @@ func TestGetServiceAccountDetails(t *testing.T) {
assert.Equal(mockResponse.Policy, serviceAccount.Policy) assert.Equal(mockResponse.Policy, serviceAccount.Policy)
// Test-2: getServiceAccountPolicy returns an error, handle it properly // Test-2: getServiceAccountPolicy returns an error, handle it properly
minioInfoServiceAccountMock = func(ctx context.Context, user string) (madmin.InfoServiceAccountResp, error) { minioInfoServiceAccountMock = func(_ context.Context, _ string) (madmin.InfoServiceAccountResp, error) {
return madmin.InfoServiceAccountResp{}, errors.New("error") return madmin.InfoServiceAccountResp{}, errors.New("error")
} }
_, err = getServiceAccountDetails(ctx, client, "") _, err = getServiceAccountDetails(ctx, client, "")

View File

@@ -75,7 +75,7 @@ func Test_changePassword(t *testing.T) {
newSecretKey: "TESTTEST2", newSecretKey: "TESTTEST2",
}, },
mock: func() { mock: func() {
minioChangePasswordMock = func(ctx context.Context, accessKey, secretKey string) error { minioChangePasswordMock = func(_ context.Context, _, _ string) error {
return nil return nil
} }
}, },
@@ -92,7 +92,7 @@ func Test_changePassword(t *testing.T) {
newSecretKey: "TESTTEST2", newSecretKey: "TESTTEST2",
}, },
mock: func() { mock: func() {
minioChangePasswordMock = func(ctx context.Context, accessKey, secretKey string) error { minioChangePasswordMock = func(_ context.Context, _, _ string) error {
return errors.New("there was an error, please try again") return errors.New("there was an error, please try again")
} }
}, },
@@ -110,7 +110,7 @@ func Test_changePassword(t *testing.T) {
newSecretKey: "TESTTEST2", newSecretKey: "TESTTEST2",
}, },
mock: func() { mock: func() {
minioChangePasswordMock = func(ctx context.Context, accessKey, secretKey string) error { minioChangePasswordMock = func(_ context.Context, _, _ string) error {
return errors.New("there was an error, please try again") return errors.New("there was an error, please try again")
} }
}, },
@@ -118,7 +118,7 @@ func Test_changePassword(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.mock != nil { if tt.mock != nil {
tt.mock() tt.mock()
} }

View File

@@ -648,7 +648,6 @@ func getPutBucketTagsResponse(session *models.Principal, params bucketApi.PutBuc
} }
err = minioClient.SetBucketTagging(ctx, bucketName, newTagSet) err = minioClient.SetBucketTagging(ctx, bucketName, newTagSet)
if err != nil { if err != nil {
return ErrorWithContext(ctx, err) return ErrorWithContext(ctx, err)
} }

View File

@@ -69,7 +69,7 @@ func TestAddBucketNotification(t *testing.T) {
testPrefix := "" testPrefix := ""
testSuffix := "" testSuffix := ""
testIgnoreExisting := false testIgnoreExisting := false
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error { mcAddNotificationConfigMock = func(_ context.Context, _ string, _ []string, _, _ string, _ bool) *probe.Error {
return nil return nil
} }
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil { if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
@@ -85,7 +85,7 @@ func TestAddBucketNotification(t *testing.T) {
testPrefix = "photos/" testPrefix = "photos/"
testSuffix = ".jpg" testSuffix = ".jpg"
testIgnoreExisting = true testIgnoreExisting = true
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error { mcAddNotificationConfigMock = func(_ context.Context, _ string, _ []string, _, _ string, _ bool) *probe.Error {
return nil return nil
} }
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil { if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
@@ -93,7 +93,7 @@ func TestAddBucketNotification(t *testing.T) {
} }
// Test-3 createBucketEvent() S3Client.AddNotificationConfig returns an error and is handled correctly // Test-3 createBucketEvent() S3Client.AddNotificationConfig returns an error and is handled correctly
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error { mcAddNotificationConfigMock = func(_ context.Context, _ string, _ []string, _, _ string, _ bool) *probe.Error {
return probe.NewError(errors.New("error")) return probe.NewError(errors.New("error"))
} }
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); assert.Error(err) { if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); assert.Error(err) {
@@ -118,7 +118,7 @@ func TestDeleteBucketNotification(t *testing.T) {
} }
prefix := "/photos" prefix := "/photos"
suffix := ".jpg" suffix := ".jpg"
mcRemoveNotificationConfigMock = func(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error { mcRemoveNotificationConfigMock = func(_ context.Context, _ string, _ string, _ string, _ string) *probe.Error {
return nil return nil
} }
if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); err != nil { if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); err != nil {
@@ -126,7 +126,7 @@ func TestDeleteBucketNotification(t *testing.T) {
} }
// Test-2 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly // Test-2 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly
mcRemoveNotificationConfigMock = func(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error { mcRemoveNotificationConfigMock = func(_ context.Context, _ string, _ string, _ string, _ string) *probe.Error {
return probe.NewError(errors.New("error")) return probe.NewError(errors.New("error"))
} }
if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); assert.Error(err) { if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); assert.Error(err) {
@@ -191,7 +191,7 @@ func TestListBucketEvents(t *testing.T) {
}, },
}, },
} }
minioGetBucketNotificationMock = func(ctx context.Context, bucketName string) (bucketNotification notification.Configuration, err error) { minioGetBucketNotificationMock = func(_ context.Context, _ string) (bucketNotification notification.Configuration, err error) {
return mockBucketN, nil return mockBucketN, nil
} }
eventConfigs, err := listBucketEvents(minClient, "bucket") eventConfigs, err := listBucketEvents(minClient, "bucket")
@@ -238,7 +238,7 @@ func TestListBucketEvents(t *testing.T) {
}, },
}, },
} }
minioGetBucketNotificationMock = func(ctx context.Context, bucketName string) (bucketNotification notification.Configuration, err error) { minioGetBucketNotificationMock = func(_ context.Context, _ string) (bucketNotification notification.Configuration, err error) {
return mockBucketN, nil return mockBucketN, nil
} }
eventConfigs, err = listBucketEvents(minClient, "bucket") eventConfigs, err = listBucketEvents(minClient, "bucket")
@@ -357,7 +357,7 @@ func TestListBucketEvents(t *testing.T) {
}, },
}, },
} }
minioGetBucketNotificationMock = func(ctx context.Context, bucketName string) (bucketNotification notification.Configuration, err error) { minioGetBucketNotificationMock = func(_ context.Context, _ string) (bucketNotification notification.Configuration, err error) {
return mockBucketN, nil return mockBucketN, nil
} }
eventConfigs, err = listBucketEvents(minClient, "bucket") eventConfigs, err = listBucketEvents(minClient, "bucket")
@@ -378,7 +378,7 @@ func TestListBucketEvents(t *testing.T) {
} }
////// Test-2 : listBucketEvents() Returns error and see that the error is handled correctly and returned ////// Test-2 : listBucketEvents() Returns error and see that the error is handled correctly and returned
minioGetBucketNotificationMock = func(ctx context.Context, bucketName string) (bucketNotification notification.Configuration, err error) { minioGetBucketNotificationMock = func(_ context.Context, _ string) (bucketNotification notification.Configuration, err error) {
return notification.Configuration{}, errors.New("error") return notification.Configuration{}, errors.New("error")
} }
_, err = listBucketEvents(minClient, "bucket") _, err = listBucketEvents(minClient, "bucket")

View File

@@ -81,7 +81,7 @@ func TestGetLifecycleRules(t *testing.T) {
}, },
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycle, nil return &mockLifecycle, nil
} }
@@ -110,7 +110,7 @@ func TestGetLifecycleRules(t *testing.T) {
Lifecycle: []*models.ObjectBucketLifecycle{}, Lifecycle: []*models.ObjectBucketLifecycle{},
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycleT2, nil return &mockLifecycleT2, nil
} }
@@ -123,7 +123,7 @@ func TestGetLifecycleRules(t *testing.T) {
// Test-3 : getBucketLifecycle() get list of events returns an error // Test-3 : getBucketLifecycle() get list of events returns an error
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return nil, errors.New("error returned") return nil, errors.New("error returned")
} }
@@ -159,7 +159,7 @@ func TestSetLifecycleRule(t *testing.T) {
}, },
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycle, nil return &mockLifecycle, nil
} }
@@ -182,7 +182,7 @@ func TestSetLifecycleRule(t *testing.T) {
}, },
} }
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return nil return nil
} }
@@ -192,7 +192,7 @@ func TestSetLifecycleRule(t *testing.T) {
// Test-2 : addBucketLifecycle() returns error // Test-2 : addBucketLifecycle() returns error
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return errors.New("error setting lifecycle") return errors.New("error setting lifecycle")
} }
@@ -223,7 +223,7 @@ func TestUpdateLifecycleRule(t *testing.T) {
}, },
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycle, nil return &mockLifecycle, nil
} }
@@ -249,7 +249,7 @@ func TestUpdateLifecycleRule(t *testing.T) {
LifecycleID: "TESTRULE", LifecycleID: "TESTRULE",
} }
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return nil return nil
} }
@@ -277,7 +277,7 @@ func TestUpdateLifecycleRule(t *testing.T) {
LifecycleID: "TESTRULE", LifecycleID: "TESTRULE",
} }
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return nil return nil
} }
@@ -287,7 +287,7 @@ func TestUpdateLifecycleRule(t *testing.T) {
// Test-3 : editBucketLifecycle() returns error // Test-3 : editBucketLifecycle() returns error
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return errors.New("error setting lifecycle") return errors.New("error setting lifecycle")
} }
@@ -305,7 +305,7 @@ func TestDeleteLifecycleRule(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
minioSetBucketLifecycleMock = func(ctx context.Context, bucketName string, config *lifecycle.Configuration) error { minioSetBucketLifecycleMock = func(_ context.Context, _ string, _ *lifecycle.Configuration) error {
return nil return nil
} }
@@ -328,7 +328,7 @@ func TestDeleteLifecycleRule(t *testing.T) {
}, },
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycle, nil return &mockLifecycle, nil
} }
@@ -360,7 +360,7 @@ func TestDeleteLifecycleRule(t *testing.T) {
Rules: []lifecycle.Rule{}, Rules: []lifecycle.Rule{},
} }
minioGetLifecycleRulesMock = func(ctx context.Context, bucketName string) (lifecycle *lifecycle.Configuration, err error) { minioGetLifecycleRulesMock = func(_ context.Context, _ string) (lifecycle *lifecycle.Configuration, err error) {
return &mockLifecycle2, nil return &mockLifecycle2, nil
} }

View File

@@ -145,7 +145,7 @@ func TestMakeBucket(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// Test-1: makeBucket() create a bucket // Test-1: makeBucket() create a bucket
// mock function response from makeBucketWithContext(ctx) // mock function response from makeBucketWithContext(ctx)
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string, objectLock bool) error { minioMakeBucketWithContextMock = func(_ context.Context, _, _ string, _ bool) error {
return nil return nil
} }
if err := makeBucket(ctx, minClient, "bucktest1", true); err != nil { if err := makeBucket(ctx, minClient, "bucktest1", true); err != nil {
@@ -153,7 +153,7 @@ func TestMakeBucket(t *testing.T) {
} }
// Test-2 makeBucket() make sure errors are handled correctly when errors on MakeBucketWithContext // Test-2 makeBucket() make sure errors are handled correctly when errors on MakeBucketWithContext
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string, objectLock bool) error { minioMakeBucketWithContextMock = func(_ context.Context, _, _ string, _ bool) error {
return errors.New("error") return errors.New("error")
} }
if err := makeBucket(ctx, minClient, "bucktest1", true); assert.Error(err) { if err := makeBucket(ctx, minClient, "bucktest1", true); assert.Error(err) {
@@ -169,7 +169,7 @@ func TestDeleteBucket(t *testing.T) {
// Test-1: removeBucket() delete a bucket // Test-1: removeBucket() delete a bucket
// mock function response from removeBucket(bucketName) // mock function response from removeBucket(bucketName)
minioRemoveBucketMock = func(bucketName string) error { minioRemoveBucketMock = func(_ string) error {
return nil return nil
} }
if err := removeBucket(minClient, "bucktest1"); err != nil { if err := removeBucket(minClient, "bucktest1"); err != nil {
@@ -178,7 +178,7 @@ func TestDeleteBucket(t *testing.T) {
// Test-2: removeBucket() make sure errors are handled correctly when errors on DeleteBucket() // Test-2: removeBucket() make sure errors are handled correctly when errors on DeleteBucket()
// mock function response from removeBucket(bucketName) // mock function response from removeBucket(bucketName)
minioRemoveBucketMock = func(bucketName string) error { minioRemoveBucketMock = func(_ string) error {
return errors.New("error") return errors.New("error")
} }
if err := removeBucket(minClient, "bucktest1"); assert.Error(err) { if err := removeBucket(minClient, "bucktest1"); assert.Error(err) {
@@ -197,7 +197,7 @@ func TestBucketInfo(t *testing.T) {
// Test-1: getBucketInfo() get a bucket with PRIVATE access // Test-1: getBucketInfo() get a bucket with PRIVATE access
// if not policy set on bucket, access should be PRIVATE // if not policy set on bucket, access should be PRIVATE
mockPolicy := "" mockPolicy := ""
minioGetBucketPolicyMock = func(bucketName string) (string, error) { minioGetBucketPolicyMock = func(_ string) (string, error) {
return mockPolicy, nil return mockPolicy, nil
} }
bucketToSet := "csbucket" bucketToSet := "csbucket"
@@ -239,7 +239,7 @@ func TestBucketInfo(t *testing.T) {
Policy: []byte(infoPolicy), Policy: []byte(infoPolicy),
} }
// mock function response from listBucketsWithContext(ctx) // mock function response from listBucketsWithContext(ctx)
minioAccountInfoMock = func(ctx context.Context) (madmin.AccountInfo, error) { minioAccountInfoMock = func(_ context.Context) (madmin.AccountInfo, error) {
return mockBucketList, nil return mockBucketList, nil
} }
@@ -256,7 +256,7 @@ func TestBucketInfo(t *testing.T) {
// Test-2: getBucketInfo() get a bucket with PUBLIC access // Test-2: getBucketInfo() get a bucket with PUBLIC access
// mock policy for bucket csbucket with readWrite access (should return PUBLIC) // mock policy for bucket csbucket with readWrite access (should return PUBLIC)
mockPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\",\"s3:ListBucketMultipartUploads\"],\"Resource\":[\"arn:aws:s3:::csbucket\"]},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetObject\",\"s3:ListMultipartUploadParts\",\"s3:PutObject\",\"s3:AbortMultipartUpload\",\"s3:DeleteObject\"],\"Resource\":[\"arn:aws:s3:::csbucket/*\"]}]}" mockPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\",\"s3:ListBucketMultipartUploads\"],\"Resource\":[\"arn:aws:s3:::csbucket\"]},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetObject\",\"s3:ListMultipartUploadParts\",\"s3:PutObject\",\"s3:AbortMultipartUpload\",\"s3:DeleteObject\"],\"Resource\":[\"arn:aws:s3:::csbucket/*\"]}]}"
minioGetBucketPolicyMock = func(bucketName string) (string, error) { minioGetBucketPolicyMock = func(_ string) (string, error) {
return mockPolicy, nil return mockPolicy, nil
} }
bucketToSet = "csbucket" bucketToSet = "csbucket"
@@ -278,9 +278,9 @@ func TestBucketInfo(t *testing.T) {
assert.Equal(outputExpected.Objects, bucketInfo.Objects) assert.Equal(outputExpected.Objects, bucketInfo.Objects)
// Test-3: getBucketInfo() get a bucket with PRIVATE access // Test-3: getBucketInfo() get a bucket with PRIVATE access
// if bucket has a null statement, the the bucket is PRIVATE // if bucket has a null statement, the bucket is PRIVATE
mockPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}" mockPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}"
minioGetBucketPolicyMock = func(bucketName string) (string, error) { minioGetBucketPolicyMock = func(_ string) (string, error) {
return mockPolicy, nil return mockPolicy, nil
} }
bucketToSet = "csbucket" bucketToSet = "csbucket"
@@ -303,7 +303,7 @@ func TestBucketInfo(t *testing.T) {
// Test-4: getBucketInfo() returns an errors while parsing invalid policy // Test-4: getBucketInfo() returns an errors while parsing invalid policy
mockPolicy = "policyinvalid" mockPolicy = "policyinvalid"
minioGetBucketPolicyMock = func(bucketName string) (string, error) { minioGetBucketPolicyMock = func(_ string) (string, error) {
return mockPolicy, nil return mockPolicy, nil
} }
bucketToSet = "csbucket" bucketToSet = "csbucket"
@@ -331,7 +331,7 @@ func TestSetBucketAccess(t *testing.T) {
function := "setBucketAccessPolicy()" function := "setBucketAccessPolicy()"
// Test-1: setBucketAccessPolicy() set a bucket's access policy // Test-1: setBucketAccessPolicy() set a bucket's access policy
// mock function response from setBucketPolicyWithContext(ctx) // mock function response from setBucketPolicyWithContext(ctx)
minioSetBucketPolicyWithContextMock = func(ctx context.Context, bucketName, policy string) error { minioSetBucketPolicyWithContextMock = func(_ context.Context, _, _ string) error {
return nil return nil
} }
if err := setBucketAccessPolicy(ctx, minClient, "bucktest1", models.BucketAccessPUBLIC, ""); err != nil { if err := setBucketAccessPolicy(ctx, minClient, "bucktest1", models.BucketAccessPUBLIC, ""); err != nil {
@@ -359,7 +359,7 @@ func TestSetBucketAccess(t *testing.T) {
} }
// Test-5: setBucketAccessPolicy() handle errors on SetPolicy call // Test-5: setBucketAccessPolicy() handle errors on SetPolicy call
minioSetBucketPolicyWithContextMock = func(ctx context.Context, bucketName, policy string) error { minioSetBucketPolicyWithContextMock = func(_ context.Context, _, _ string) error {
return errors.New("error") return errors.New("error")
} }
if err := setBucketAccessPolicy(ctx, minClient, "bucktest1", models.BucketAccessPUBLIC, ""); assert.Error(err) { if err := setBucketAccessPolicy(ctx, minClient, "bucktest1", models.BucketAccessPUBLIC, ""); assert.Error(err) {
@@ -390,7 +390,7 @@ func Test_enableBucketEncryption(t *testing.T) {
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
encryptionType: "sse-s3", encryptionType: "sse-s3",
mockEnableBucketEncryptionFunc: func(ctx context.Context, bucketName string, config *sse.Configuration) error { mockEnableBucketEncryptionFunc: func(_ context.Context, _ string, _ *sse.Configuration) error {
return nil return nil
}, },
}, },
@@ -403,7 +403,7 @@ func Test_enableBucketEncryption(t *testing.T) {
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
encryptionType: "sse-s3", encryptionType: "sse-s3",
mockEnableBucketEncryptionFunc: func(ctx context.Context, bucketName string, config *sse.Configuration) error { mockEnableBucketEncryptionFunc: func(_ context.Context, _ string, _ *sse.Configuration) error {
return ErrInvalidSession return ErrInvalidSession
}, },
}, },
@@ -411,7 +411,7 @@ func Test_enableBucketEncryption(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioSetBucketEncryptionMock = tt.args.mockEnableBucketEncryptionFunc minioSetBucketEncryptionMock = tt.args.mockEnableBucketEncryptionFunc
if err := enableBucketEncryption(tt.args.ctx, tt.args.client, tt.args.bucketName, tt.args.encryptionType, tt.args.kmsKeyID); (err != nil) != tt.wantErr { if err := enableBucketEncryption(tt.args.ctx, tt.args.client, tt.args.bucketName, tt.args.encryptionType, tt.args.kmsKeyID); (err != nil) != tt.wantErr {
t.Errorf("enableBucketEncryption() errors = %v, wantErr %v", err, tt.wantErr) t.Errorf("enableBucketEncryption() errors = %v, wantErr %v", err, tt.wantErr)
@@ -440,7 +440,7 @@ func Test_disableBucketEncryption(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
mockBucketDisableFunc: func(ctx context.Context, bucketName string) error { mockBucketDisableFunc: func(_ context.Context, _ string) error {
return nil return nil
}, },
}, },
@@ -452,7 +452,7 @@ func Test_disableBucketEncryption(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
mockBucketDisableFunc: func(ctx context.Context, bucketName string) error { mockBucketDisableFunc: func(_ context.Context, _ string) error {
return ErrDefault return ErrDefault
}, },
}, },
@@ -460,7 +460,7 @@ func Test_disableBucketEncryption(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioRemoveBucketEncryptionMock = tt.args.mockBucketDisableFunc minioRemoveBucketEncryptionMock = tt.args.mockBucketDisableFunc
if err := disableBucketEncryption(tt.args.ctx, tt.args.client, tt.args.bucketName); (err != nil) != tt.wantErr { if err := disableBucketEncryption(tt.args.ctx, tt.args.client, tt.args.bucketName); (err != nil) != tt.wantErr {
t.Errorf("disableBucketEncryption() errors = %v, wantErr %v", err, tt.wantErr) t.Errorf("disableBucketEncryption() errors = %v, wantErr %v", err, tt.wantErr)
@@ -490,7 +490,7 @@ func Test_getBucketEncryptionInfo(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
mockBucketEncryptionGet: func(ctx context.Context, bucketName string) (*sse.Configuration, error) { mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
return &sse.Configuration{ return &sse.Configuration{
Rules: []sse.Rule{ Rules: []sse.Rule{
{ {
@@ -512,7 +512,7 @@ func Test_getBucketEncryptionInfo(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
mockBucketEncryptionGet: func(ctx context.Context, bucketName string) (*sse.Configuration, error) { mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
return &sse.Configuration{ return &sse.Configuration{
Rules: []sse.Rule{}, Rules: []sse.Rule{},
}, nil }, nil
@@ -526,7 +526,7 @@ func Test_getBucketEncryptionInfo(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
mockBucketEncryptionGet: func(ctx context.Context, bucketName string) (*sse.Configuration, error) { mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
return nil, ErrSSENotConfigured return nil, ErrSSENotConfigured
}, },
}, },
@@ -534,7 +534,7 @@ func Test_getBucketEncryptionInfo(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioGetBucketEncryptionMock = tt.args.mockBucketEncryptionGet minioGetBucketEncryptionMock = tt.args.mockBucketEncryptionGet
got, err := getBucketEncryptionInfo(tt.args.ctx, tt.args.client, tt.args.bucketName) got, err := getBucketEncryptionInfo(tt.args.ctx, tt.args.client, tt.args.bucketName)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
@@ -575,7 +575,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionModeCompliance, mode: models.ObjectRetentionModeCompliance,
unit: models.ObjectRetentionUnitDays, unit: models.ObjectRetentionUnitDays,
validity: swag.Int32(2), validity: swag.Int32(2),
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return nil return nil
}, },
}, },
@@ -590,7 +590,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionModeGovernance, mode: models.ObjectRetentionModeGovernance,
unit: models.ObjectRetentionUnitYears, unit: models.ObjectRetentionUnitYears,
validity: swag.Int32(2), validity: swag.Int32(2),
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return nil return nil
}, },
}, },
@@ -605,7 +605,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionModeCompliance, mode: models.ObjectRetentionModeCompliance,
unit: models.ObjectRetentionUnitDays, unit: models.ObjectRetentionUnitDays,
validity: nil, validity: nil,
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return nil return nil
}, },
}, },
@@ -620,7 +620,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionMode("othermode"), mode: models.ObjectRetentionMode("othermode"),
unit: models.ObjectRetentionUnitDays, unit: models.ObjectRetentionUnitDays,
validity: swag.Int32(2), validity: swag.Int32(2),
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return nil return nil
}, },
}, },
@@ -635,7 +635,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionModeCompliance, mode: models.ObjectRetentionModeCompliance,
unit: models.ObjectRetentionUnit("otherunit"), unit: models.ObjectRetentionUnit("otherunit"),
validity: swag.Int32(2), validity: swag.Int32(2),
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return nil return nil
}, },
}, },
@@ -650,7 +650,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
mode: models.ObjectRetentionModeCompliance, mode: models.ObjectRetentionModeCompliance,
unit: models.ObjectRetentionUnitDays, unit: models.ObjectRetentionUnitDays,
validity: swag.Int32(2), validity: swag.Int32(2),
mockBucketRetentionFunc: func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error { mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
return errors.New("error func") return errors.New("error func")
}, },
}, },
@@ -658,7 +658,7 @@ func Test_SetBucketRetentionConfig(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioSetObjectLockConfigMock = tt.args.mockBucketRetentionFunc minioSetObjectLockConfigMock = tt.args.mockBucketRetentionFunc
err := setBucketRetentionConfig(tt.args.ctx, tt.args.client, tt.args.bucketName, tt.args.mode, tt.args.unit, tt.args.validity) err := setBucketRetentionConfig(tt.args.ctx, tt.args.client, tt.args.bucketName, tt.args.mode, tt.args.unit, tt.args.validity)
if tt.expectedError != nil { if tt.expectedError != nil {
@@ -693,7 +693,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
m := minio.Governance m := minio.Governance
u := minio.Days u := minio.Days
return &m, swag.Uint(2), &u, nil return &m, swag.Uint(2), &u, nil
@@ -712,7 +712,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
m := minio.Compliance m := minio.Compliance
u := minio.Days u := minio.Days
return &m, swag.Uint(2), &u, nil return &m, swag.Uint(2), &u, nil
@@ -731,7 +731,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
return nil, nil, nil, errors.New("error func") return nil, nil, nil, errors.New("error func")
}, },
}, },
@@ -746,7 +746,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
return nil, nil, nil, minio.ErrorResponse{ return nil, nil, nil, minio.ErrorResponse{
Code: "ObjectLockConfigurationNotFoundError", Code: "ObjectLockConfigurationNotFoundError",
Message: "Object Lock configuration does not exist for this bucket", Message: "Object Lock configuration does not exist for this bucket",
@@ -762,7 +762,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
m := minio.RetentionMode("other") m := minio.RetentionMode("other")
u := minio.Days u := minio.Days
return &m, swag.Uint(2), &u, nil return &m, swag.Uint(2), &u, nil
@@ -777,7 +777,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
ctx: ctx, ctx: ctx,
client: minClient, client: minClient,
bucketName: "test", bucketName: "test",
getRetentionFunc: func(ctx context.Context, bucketName string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) { getRetentionFunc: func(_ context.Context, _ string) (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, err error) {
m := minio.Governance m := minio.Governance
u := minio.ValidityUnit("otherUnit") u := minio.ValidityUnit("otherUnit")
return &m, swag.Uint(2), &u, nil return &m, swag.Uint(2), &u, nil
@@ -789,7 +789,7 @@ func Test_GetBucketRetentionConfig(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioGetBucketObjectLockConfigMock = tt.args.getRetentionFunc minioGetBucketObjectLockConfigMock = tt.args.getRetentionFunc
resp, err := getBucketRetentionConfig(tt.args.ctx, tt.args.client, tt.args.bucketName) resp, err := getBucketRetentionConfig(tt.args.ctx, tt.args.client, tt.args.bucketName)
@@ -833,7 +833,7 @@ func Test_SetBucketVersioning(t *testing.T) {
state: VersionEnable, state: VersionEnable,
bucketName: "test", bucketName: "test",
client: minClient, client: minClient,
setVersioningFunc: func(ctx context.Context, state string, excludePrefix []string, excludeFolders bool) *probe.Error { setVersioningFunc: func(_ context.Context, _ string, _ []string, _ bool) *probe.Error {
return nil return nil
}, },
}, },
@@ -847,7 +847,7 @@ func Test_SetBucketVersioning(t *testing.T) {
excludePrefix: []string{"prefix1", "prefix2"}, excludePrefix: []string{"prefix1", "prefix2"},
bucketName: "test", bucketName: "test",
client: minClient, client: minClient,
setVersioningFunc: func(ctx context.Context, state string, excludePrefix []string, excludeFolders bool) *probe.Error { setVersioningFunc: func(_ context.Context, _ string, _ []string, _ bool) *probe.Error {
return nil return nil
}, },
}, },
@@ -862,7 +862,7 @@ func Test_SetBucketVersioning(t *testing.T) {
excludeFolders: true, excludeFolders: true,
bucketName: "test", bucketName: "test",
client: minClient, client: minClient,
setVersioningFunc: func(ctx context.Context, state string, excludePrefix []string, excludeFolders bool) *probe.Error { setVersioningFunc: func(_ context.Context, _ string, _ []string, _ bool) *probe.Error {
return nil return nil
}, },
}, },
@@ -875,7 +875,7 @@ func Test_SetBucketVersioning(t *testing.T) {
state: VersionEnable, state: VersionEnable,
bucketName: "test", bucketName: "test",
client: minClient, client: minClient,
setVersioningFunc: func(ctx context.Context, state string, excludePrefix []string, excludeFolders bool) *probe.Error { setVersioningFunc: func(_ context.Context, _ string, _ []string, _ bool) *probe.Error {
return probe.NewError(errors.New(errorMsg)) return probe.NewError(errors.New(errorMsg))
}, },
}, },
@@ -884,7 +884,7 @@ func Test_SetBucketVersioning(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
minioSetVersioningMock = tt.args.setVersioningFunc minioSetVersioningMock = tt.args.setVersioningFunc
err := doSetVersioning(tt.args.ctx, tt.args.client, tt.args.state, tt.args.excludePrefix, tt.args.excludeFolders) err := doSetVersioning(tt.args.ctx, tt.args.client, tt.args.state, tt.args.excludePrefix, tt.args.excludeFolders)
@@ -1199,9 +1199,9 @@ func Test_getAccountBuckets(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// mock function response from listBucketsWithContext(ctx) // mock function response from listBucketsWithContext(ctx)
minioAccountInfoMock = func(ctx context.Context) (madmin.AccountInfo, error) { minioAccountInfoMock = func(_ context.Context) (madmin.AccountInfo, error) {
return tt.args.mockBucketList, tt.args.mockError return tt.args.mockBucketList, tt.args.mockError
} }
client := AdminClientMock{} client := AdminClientMock{}
@@ -1268,7 +1268,7 @@ func Test_getMaxShareLinkExpirationSeconds(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.preFunc != nil { if tt.preFunc != nil {
tt.preFunc() tt.preFunc()
} }

View File

@@ -97,8 +97,8 @@ func TestLogSearch(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
testRequest := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { testRequest := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(tt.args.apiResponseCode) w.WriteHeader(tt.args.apiResponseCode)
fmt.Fprintln(w, tt.args.apiResponse) fmt.Fprintln(w, tt.args.apiResponse)
})) }))

View File

@@ -125,14 +125,14 @@ func Test_validateUserAgainstIDP(t *testing.T) {
want: nil, want: nil,
wantErr: true, wantErr: true,
mockFunc: func() { mockFunc: func() {
idpVerifyIdentityMock = func(ctx context.Context, code, state string) (*credentials.Credentials, error) { idpVerifyIdentityMock = func(_ context.Context, _, _ string) (*credentials.Credentials, error) {
return nil, errors.New("something went wrong") return nil, errors.New("something went wrong")
} }
}, },
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.mockFunc != nil { if tt.mockFunc != nil {
tt.mockFunc() tt.mockFunc()
} }
@@ -170,14 +170,14 @@ func Test_getAccountInfo(t *testing.T) {
want: nil, want: nil,
wantErr: true, wantErr: true,
mockFunc: func() { mockFunc: func() {
minioAccountInfoMock = func(ctx context.Context) (madmin.AccountInfo, error) { minioAccountInfoMock = func(_ context.Context) (madmin.AccountInfo, error) {
return madmin.AccountInfo{}, errors.New("something went wrong") return madmin.AccountInfo{}, errors.New("something went wrong")
} }
}, },
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.mockFunc != nil { if tt.mockFunc != nil {
tt.mockFunc() tt.mockFunc()
} }

View File

@@ -1045,7 +1045,6 @@ func uploadFiles(ctx context.Context, client MinioClient, params objectApi.PostB
ContentType: contentType, ContentType: contentType,
DisableMultipart: true, // Do not upload as multipart stream for console uploader. DisableMultipart: true, // Do not upload as multipart stream for console uploader.
}) })
if err != nil { if err != nil {
return err return err
} }

View File

@@ -145,7 +145,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -168,15 +168,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -222,20 +222,20 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
defer close(objectStatCh) defer close(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -257,7 +257,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -277,15 +277,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -309,7 +309,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -333,15 +333,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -385,7 +385,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -402,13 +402,13 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
return nil, errors.New("error legal") return nil, errors.New("error legal")
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
return nil, nil, errors.New("error retention") return nil, nil, errors.New("error retention")
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
return nil, errors.New("error get tags") return nil, errors.New("error get tags")
}, },
}, },
@@ -433,7 +433,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -456,15 +456,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -501,7 +501,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -524,15 +524,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -566,7 +566,7 @@ func Test_listObjects(t *testing.T) {
recursive: true, recursive: true,
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -589,15 +589,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -644,7 +644,7 @@ func Test_listObjects(t *testing.T) {
withVersions: false, withVersions: false,
withMetadata: false, withMetadata: false,
limit: swag.Int32(1), limit: swag.Int32(1),
listFunc: func(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo { listFunc: func(_ context.Context, _ string, _ minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objectStatCh := make(chan minio.ObjectInfo, 1) objectStatCh := make(chan minio.ObjectInfo, 1)
go func(objectStatCh chan<- minio.ObjectInfo) { go func(objectStatCh chan<- minio.ObjectInfo) {
defer close(objectStatCh) defer close(objectStatCh)
@@ -667,15 +667,15 @@ func Test_listObjects(t *testing.T) {
}(objectStatCh) }(objectStatCh)
return objectStatCh return objectStatCh
}, },
objectLegalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) { objectLegalHoldFunc: func(_ context.Context, _, _ string, _ minio.GetObjectLegalHoldOptions) (status *minio.LegalHoldStatus, err error) {
s := minio.LegalHoldEnabled s := minio.LegalHoldEnabled
return &s, nil return &s, nil
}, },
objectRetentionFunc: func(ctx context.Context, bucketName, objectName, versionID string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) { objectRetentionFunc: func(_ context.Context, _, _, _ string) (mode *minio.RetentionMode, retainUntilDate *time.Time, err error) {
m := minio.Governance m := minio.Governance
return &m, &tretention, nil return &m, &tretention, nil
}, },
objectGetTaggingFunc: func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error) { objectGetTaggingFunc: func(_ context.Context, _, _ string, _ minio.GetObjectTaggingOptions) (*tags.Tags, error) {
tagMap := map[string]string{ tagMap := map[string]string{
"tag1": "value1", "tag1": "value1",
} }
@@ -707,7 +707,7 @@ func Test_listObjects(t *testing.T) {
t.Parallel() t.Parallel()
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
minioListObjectsMock = tt.args.listFunc minioListObjectsMock = tt.args.listFunc
minioGetObjectLegalHoldMock = tt.args.objectLegalHoldFunc minioGetObjectLegalHoldMock = tt.args.objectLegalHoldFunc
minioGetObjectRetentionMock = tt.args.objectRetentionFunc minioGetObjectRetentionMock = tt.args.objectRetentionFunc
@@ -768,7 +768,7 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: false, recursive: false,
nonCurrent: false, nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil} resultCh <- mc.RemoveResult{Err: nil}
close(resultCh) close(resultCh)
@@ -784,7 +784,7 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: false, recursive: false,
nonCurrent: false, nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))} resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
close(resultCh) close(resultCh)
@@ -800,13 +800,13 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: true, recursive: true,
nonCurrent: false, nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil} resultCh <- mc.RemoveResult{Err: nil}
close(resultCh) close(resultCh)
return resultCh return resultCh
}, },
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent { listFunc: func(_ context.Context, _ mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1) ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{} ch <- &mc.ClientContent{}
close(ch) close(ch)
@@ -824,13 +824,13 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: true, recursive: true,
nonCurrent: false, nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))} resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
close(resultCh) close(resultCh)
return resultCh return resultCh
}, },
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent { listFunc: func(_ context.Context, _ mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1) ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{} ch <- &mc.ClientContent{}
close(ch) close(ch)
@@ -846,13 +846,13 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: true, recursive: true,
nonCurrent: true, nonCurrent: true,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil} resultCh <- mc.RemoveResult{Err: nil}
close(resultCh) close(resultCh)
return resultCh return resultCh
}, },
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent { listFunc: func(_ context.Context, _ mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1) ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{} ch <- &mc.ClientContent{}
close(ch) close(ch)
@@ -870,13 +870,13 @@ func Test_deleteObjects(t *testing.T) {
versionID: "", versionID: "",
recursive: true, recursive: true,
nonCurrent: true, nonCurrent: true,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, forceDelete bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult { removeFunc: func(_ context.Context, _, _, _, _ bool, _ <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1) resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))} resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
close(resultCh) close(resultCh)
return resultCh return resultCh
}, },
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent { listFunc: func(_ context.Context, _ mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1) ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{} ch <- &mc.ClientContent{}
close(ch) close(ch)
@@ -890,7 +890,7 @@ func Test_deleteObjects(t *testing.T) {
t.Parallel() t.Parallel()
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
mcListMock = tt.args.listFunc mcListMock = tt.args.listFunc
mcRemoveMock = tt.args.removeFunc mcRemoveMock = tt.args.removeFunc
err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false, tt.args.nonCurrent, false) err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false, tt.args.nonCurrent, false)
@@ -929,7 +929,7 @@ func Test_shareObject(t *testing.T) {
args: args{ args: args{
versionID: "2121434", versionID: "2121434",
expires: "30s", expires: "30s",
shareFunc: func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error) { shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "http://someurl", nil return "http://someurl", nil
}, },
}, },
@@ -941,7 +941,7 @@ func Test_shareObject(t *testing.T) {
args: args{ args: args{
versionID: "2121434", versionID: "2121434",
expires: "invalid", expires: "invalid",
shareFunc: func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error) { shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "http://someurl", nil return "http://someurl", nil
}, },
}, },
@@ -952,7 +952,7 @@ func Test_shareObject(t *testing.T) {
args: args{ args: args{
versionID: "2121434", versionID: "2121434",
expires: "", expires: "",
shareFunc: func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error) { shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "http://someurl", nil return "http://someurl", nil
}, },
}, },
@@ -964,7 +964,7 @@ func Test_shareObject(t *testing.T) {
args: args{ args: args{
versionID: "2121434", versionID: "2121434",
expires: "3h", expires: "3h",
shareFunc: func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error) { shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "", probe.NewError(errors.New("probe error")) return "", probe.NewError(errors.New("probe error"))
}, },
}, },
@@ -973,7 +973,7 @@ func Test_shareObject(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
mcShareDownloadMock = tt.args.shareFunc mcShareDownloadMock = tt.args.shareFunc
url, err := getShareObjectURL(ctx, client, tt.args.versionID, tt.args.expires) url, err := getShareObjectURL(ctx, client, tt.args.versionID, tt.args.expires)
if tt.wantError != nil { if tt.wantError != nil {
@@ -1011,7 +1011,7 @@ func Test_putObjectLegalHold(t *testing.T) {
versionID: "someversion", versionID: "someversion",
prefix: "folder/file.txt", prefix: "folder/file.txt",
status: models.ObjectLegalHoldStatusEnabled, status: models.ObjectLegalHoldStatusEnabled,
legalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error { legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
return nil return nil
}, },
}, },
@@ -1024,7 +1024,7 @@ func Test_putObjectLegalHold(t *testing.T) {
versionID: "someversion", versionID: "someversion",
prefix: "folder/file.txt", prefix: "folder/file.txt",
status: models.ObjectLegalHoldStatusDisabled, status: models.ObjectLegalHoldStatusDisabled,
legalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error { legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
return nil return nil
}, },
}, },
@@ -1037,7 +1037,7 @@ func Test_putObjectLegalHold(t *testing.T) {
versionID: "someversion", versionID: "someversion",
prefix: "folder/file.txt", prefix: "folder/file.txt",
status: models.ObjectLegalHoldStatusDisabled, status: models.ObjectLegalHoldStatusDisabled,
legalHoldFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error { legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
return errors.New("new error") return errors.New("new error")
}, },
}, },
@@ -1046,7 +1046,7 @@ func Test_putObjectLegalHold(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
minioPutObjectLegalHoldMock = tt.args.legalHoldFunc minioPutObjectLegalHoldMock = tt.args.legalHoldFunc
err := setObjectLegalHold(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.status) err := setObjectLegalHold(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.status)
if !reflect.DeepEqual(err, tt.wantError) { if !reflect.DeepEqual(err, tt.wantError) {
@@ -1085,7 +1085,7 @@ func Test_putObjectRetention(t *testing.T) {
GovernanceBypass: false, GovernanceBypass: false,
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeGovernance), Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeGovernance),
}, },
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1102,7 +1102,7 @@ func Test_putObjectRetention(t *testing.T) {
GovernanceBypass: false, GovernanceBypass: false,
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance), Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
}, },
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1115,7 +1115,7 @@ func Test_putObjectRetention(t *testing.T) {
versionID: "someversion", versionID: "someversion",
prefix: "folder/file.txt", prefix: "folder/file.txt",
opts: nil, opts: nil,
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1132,7 +1132,7 @@ func Test_putObjectRetention(t *testing.T) {
GovernanceBypass: false, GovernanceBypass: false,
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance), Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
}, },
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1149,7 +1149,7 @@ func Test_putObjectRetention(t *testing.T) {
GovernanceBypass: false, GovernanceBypass: false,
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance), Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
}, },
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1166,7 +1166,7 @@ func Test_putObjectRetention(t *testing.T) {
GovernanceBypass: false, GovernanceBypass: false,
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance), Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
}, },
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return errors.New("new Error") return errors.New("new Error")
}, },
}, },
@@ -1175,7 +1175,7 @@ func Test_putObjectRetention(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
minioPutObjectRetentionMock = tt.args.retentionFunc minioPutObjectRetentionMock = tt.args.retentionFunc
err := setObjectRetention(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.opts) err := setObjectRetention(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.opts)
if tt.wantError != nil { if tt.wantError != nil {
@@ -1210,7 +1210,7 @@ func Test_deleteObjectRetention(t *testing.T) {
bucket: "buck1", bucket: "buck1",
versionID: "someversion", versionID: "someversion",
prefix: "folder/file.txt", prefix: "folder/file.txt",
retentionFunc: func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error { retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
return nil return nil
}, },
}, },
@@ -1218,7 +1218,7 @@ func Test_deleteObjectRetention(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
minioPutObjectRetentionMock = tt.args.retentionFunc minioPutObjectRetentionMock = tt.args.retentionFunc
err := deleteObjectRetention(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID) err := deleteObjectRetention(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID)
if tt.wantError != nil { if tt.wantError != nil {
@@ -1252,7 +1252,7 @@ func Test_getObjectInfo(t *testing.T) {
args: args{ args: args{
bucketName: "bucket1", bucketName: "bucket1",
prefix: "someprefix", prefix: "someprefix",
statFunc: func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (minio.ObjectInfo, error) { statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
return minio.ObjectInfo{}, nil return minio.ObjectInfo{}, nil
}, },
}, },
@@ -1263,7 +1263,7 @@ func Test_getObjectInfo(t *testing.T) {
args: args{ args: args{
bucketName: "bucket2", bucketName: "bucket2",
prefix: "someprefi2", prefix: "someprefi2",
statFunc: func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (minio.ObjectInfo, error) { statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
return minio.ObjectInfo{}, errors.New("new Error") return minio.ObjectInfo{}, errors.New("new Error")
}, },
}, },
@@ -1271,7 +1271,7 @@ func Test_getObjectInfo(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) { t.Run(tt.test, func(_ *testing.T) {
minioStatObjectMock = tt.args.statFunc minioStatObjectMock = tt.args.statFunc
_, err := getObjectInfo(ctx, client, tt.args.bucketName, tt.args.prefix) _, err := getObjectInfo(ctx, client, tt.args.bucketName, tt.args.prefix)
if tt.wantError != nil { if tt.wantError != nil {
@@ -1312,7 +1312,7 @@ func Test_getScheme(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
gotScheme, gotPath := getScheme(tt.args.rawurl) gotScheme, gotPath := getScheme(tt.args.rawurl)
assert.Equalf(t, tt.wantScheme, gotScheme, "getScheme(%v)", tt.args.rawurl) assert.Equalf(t, tt.wantScheme, gotScheme, "getScheme(%v)", tt.args.rawurl)
assert.Equalf(t, tt.wantPath, gotPath, "getScheme(%v)", tt.args.rawurl) assert.Equalf(t, tt.wantPath, gotPath, "getScheme(%v)", tt.args.rawurl)
@@ -1364,7 +1364,7 @@ func Test_splitSpecial(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, got1 := splitSpecial(tt.args.s, tt.args.delimiter, tt.args.cutdelimiter) got, got1 := splitSpecial(tt.args.s, tt.args.delimiter, tt.args.cutdelimiter)
assert.Equalf(t, tt.want, got, "splitSpecial(%v, %v, %v)", tt.args.s, tt.args.delimiter, tt.args.cutdelimiter) assert.Equalf(t, tt.want, got, "splitSpecial(%v, %v, %v)", tt.args.s, tt.args.delimiter, tt.args.cutdelimiter)
assert.Equalf(t, tt.want1, got1, "splitSpecial(%v, %v, %v)", tt.args.s, tt.args.delimiter, tt.args.cutdelimiter) assert.Equalf(t, tt.want1, got1, "splitSpecial(%v, %v, %v)", tt.args.s, tt.args.delimiter, tt.args.cutdelimiter)
@@ -1397,7 +1397,7 @@ func Test_getHost(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.wantHost, getHost(tt.args.authority), "getHost(%v)", tt.args.authority) assert.Equalf(t, tt.wantHost, getHost(tt.args.authority), "getHost(%v)", tt.args.authority)
}) })
} }
@@ -1439,7 +1439,7 @@ func Test_newClientURL(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, *newClientURL(tt.args.urlStr), "newClientURL(%v)", tt.args.urlStr) assert.Equalf(t, tt.want, *newClientURL(tt.args.urlStr), "newClientURL(%v)", tt.args.urlStr)
}) })
} }
@@ -1498,7 +1498,7 @@ func Test_getMultipleFilesDownloadResponse(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, got1 := getMultipleFilesDownloadResponse(tt.args.session, tt.args.params) got, got1 := getMultipleFilesDownloadResponse(tt.args.session, tt.args.params)
assert.Equal(t, tt.want1, got1) assert.Equal(t, tt.want1, got1)
assert.NotNil(t, got) assert.NotNil(t, got)

View File

@@ -71,7 +71,7 @@ func Test_getSessionResponse(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.preFunc != nil { if tt.preFunc != nil {
tt.preFunc() tt.preFunc()
} }
@@ -128,7 +128,7 @@ func Test_getListOfEnabledFeatures(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.preFunc != nil { if tt.preFunc != nil {
tt.preFunc() tt.preFunc()
} }

View File

@@ -166,7 +166,6 @@ func configureCallHomeDiagnostics(ctx context.Context, client MinioAdmin, diagSt
} }
configStr := "callhome enable=" + enableStr configStr := "callhome enable=" + enableStr
_, err = client.setConfigKV(ctx, configStr) _, err = client.setConfigKV(ctx, configStr)
if err != nil { if err != nil {
return err return err
} }
@@ -205,13 +204,11 @@ func setCallHomeConfiguration(ctx context.Context, client MinioAdmin, diagState,
} }
err = configureCallHomeDiagnostics(ctx, client, diagState) err = configureCallHomeDiagnostics(ctx, client, diagState)
if err != nil { if err != nil {
return err return err
} }
err = configureCallHomeLogs(ctx, client, logsState, apiKey) err = configureCallHomeLogs(ctx, client, logsState, apiKey)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -46,13 +46,13 @@ func Test_getCallHomeRule(t *testing.T) {
ctx: ctx, ctx: ctx,
session: nil, session: nil,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{}, errors.New("feature is not supported") return madmin.Help{}, errors.New("feature is not supported")
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte{}, nil return []byte{}, nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -69,7 +69,7 @@ func Test_getCallHomeRule(t *testing.T) {
ctx: ctx, ctx: ctx,
session: nil, session: nil,
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -79,7 +79,7 @@ func Test_getCallHomeRule(t *testing.T) {
}, },
}, nil }, nil
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "callhome", SubSys: "callhome",
Description: "enable callhome for the cluster", Description: "enable callhome for the cluster",
@@ -90,7 +90,7 @@ func Test_getCallHomeRule(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`callhome:_ frequency=24h enable=on`), nil return []byte(`callhome:_ frequency=24h enable=on`), nil
}, },
want: &models.CallHomeGetResponse{ want: &models.CallHomeGetResponse{
@@ -104,7 +104,7 @@ func Test_getCallHomeRule(t *testing.T) {
ctx: ctx, ctx: ctx,
session: nil, session: nil,
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -114,7 +114,7 @@ func Test_getCallHomeRule(t *testing.T) {
}, },
}, nil }, nil
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "callhome", SubSys: "callhome",
Description: "enable callhome for the cluster", Description: "enable callhome for the cluster",
@@ -125,7 +125,7 @@ func Test_getCallHomeRule(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`callhome:_ frequency=24h enable=off`), nil return []byte(`callhome:_ frequency=24h enable=off`), nil
}, },
want: &models.CallHomeGetResponse{ want: &models.CallHomeGetResponse{
@@ -136,7 +136,7 @@ func Test_getCallHomeRule(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
minioGetConfigKVMock = tt.getConfigKV minioGetConfigKVMock = tt.getConfigKV
@@ -181,13 +181,13 @@ func Test_setCallHomeConfiguration(t *testing.T) {
session: nil, session: nil,
diagState: false, diagState: false,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{}, errors.New("feature is not supported") return madmin.Help{}, errors.New("feature is not supported")
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte{}, nil return []byte{}, nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -195,7 +195,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
KeysHelp: madmin.HelpKVS{}, KeysHelp: madmin.HelpKVS{},
}, nil }, nil
}, },
setConfigEnv: func(kv string) (restart bool, err error) { setConfigEnv: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: true, wantErr: true,
@@ -208,7 +208,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
session: nil, session: nil,
diagState: false, diagState: false,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "subnet", SubSys: "subnet",
Description: "set subnet config for the cluster e.g. api key", Description: "set subnet config for the cluster e.g. api key",
@@ -220,10 +220,10 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`subnet license= api_key= proxy=http://127.0.0.1 `), nil return []byte(`subnet license= api_key= proxy=http://127.0.0.1 `), nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -233,7 +233,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
setConfigEnv: func(kv string) (restart bool, err error) { setConfigEnv: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: true, wantErr: true,
@@ -246,7 +246,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
session: nil, session: nil,
diagState: true, diagState: true,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "subnet", SubSys: "subnet",
Description: "set subnet config for the cluster e.g. api key", Description: "set subnet config for the cluster e.g. api key",
@@ -258,10 +258,10 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -271,7 +271,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
setConfigEnv: func(kv string) (restart bool, err error) { setConfigEnv: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: false, wantErr: false,
@@ -284,7 +284,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
session: nil, session: nil,
diagState: false, diagState: false,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "subnet", SubSys: "subnet",
Description: "set subnet config for the cluster e.g. api key", Description: "set subnet config for the cluster e.g. api key",
@@ -296,10 +296,10 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -309,7 +309,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
setConfigEnv: func(kv string) (restart bool, err error) { setConfigEnv: func(_ string) (restart bool, err error) {
return false, nil return false, nil
}, },
wantErr: false, wantErr: false,
@@ -322,7 +322,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
session: nil, session: nil,
diagState: false, diagState: false,
}, },
helpConfigKV: func(subSys, key string, envOnly bool) (madmin.Help, error) { helpConfigKV: func(_, _ string, _ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "subnet", SubSys: "subnet",
Description: "set subnet config for the cluster e.g. api key", Description: "set subnet config for the cluster e.g. api key",
@@ -334,10 +334,10 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
getConfigKV: func(key string) ([]byte, error) { getConfigKV: func(_ string) ([]byte, error) {
return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil return []byte(`subnet license= api_key=testAPIKey proxy=http://127.0.0.1 `), nil
}, },
helpConfigKVGlobal: func(envOnly bool) (madmin.Help, error) { helpConfigKVGlobal: func(_ bool) (madmin.Help, error) {
return madmin.Help{ return madmin.Help{
SubSys: "", SubSys: "",
Description: "", Description: "",
@@ -347,7 +347,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
}, },
}, nil }, nil
}, },
setConfigEnv: func(kv string) (restart bool, err error) { setConfigEnv: func(_ string) (restart bool, err error) {
return false, errors.New("new error detected") return false, errors.New("new error detected")
}, },
wantErr: true, wantErr: true,
@@ -356,7 +356,7 @@ func Test_setCallHomeConfiguration(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
adminClient := AdminClientMock{} adminClient := AdminClientMock{}
minioGetConfigKVMock = tt.getConfigKV minioGetConfigKVMock = tt.getConfigKV

View File

@@ -81,7 +81,7 @@ func TestWatch(t *testing.T) {
// Test-1: Serve Watch with no errors until Watch finishes sending // Test-1: Serve Watch with no errors until Watch finishes sending
// define mock function behavior // define mock function behavior
mcWatchMock = func(ctx context.Context, params mc.WatchOptions) (*mc.WatchObject, *probe.Error) { mcWatchMock = func(_ context.Context, _ mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
wo := &mc.WatchObject{ wo := &mc.WatchObject{
EventInfoChan: make(chan []mc.EventInfo), EventInfoChan: make(chan []mc.EventInfo),
ErrorChan: make(chan *probe.Error), ErrorChan: make(chan *probe.Error),
@@ -109,7 +109,7 @@ func TestWatch(t *testing.T) {
} }
writesCount := 1 writesCount := 1
// mock connection WriteMessage() no error // mock connection WriteMessage() no error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, data []byte) error {
// emulate that receiver gets the message written // emulate that receiver gets the message written
var t []mc.EventInfo var t []mc.EventInfo
_ = json.Unmarshal(data, &t) _ = json.Unmarshal(data, &t)
@@ -136,7 +136,7 @@ func TestWatch(t *testing.T) {
} }
// Test-2: if error happens while writing, return error // Test-2: if error happens while writing, return error
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return fmt.Errorf("error on write") return fmt.Errorf("error on write")
} }
if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) { if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) {
@@ -145,7 +145,7 @@ func TestWatch(t *testing.T) {
// Test-3: error happens on Watch, watch should stop // Test-3: error happens on Watch, watch should stop
// and error shall be returned. // and error shall be returned.
mcWatchMock = func(ctx context.Context, params mc.WatchOptions) (*mc.WatchObject, *probe.Error) { mcWatchMock = func(_ context.Context, _ mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
wo := &mc.WatchObject{ wo := &mc.WatchObject{
EventInfoChan: make(chan []mc.EventInfo), EventInfoChan: make(chan []mc.EventInfo),
ErrorChan: make(chan *probe.Error), ErrorChan: make(chan *probe.Error),
@@ -171,7 +171,7 @@ func TestWatch(t *testing.T) {
}(wo) }(wo)
return wo, nil return wo, nil
} }
connWriteMessageMock = func(messageType int, data []byte) error { connWriteMessageMock = func(_ int, _ []byte) error {
return nil return nil
} }
if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) { if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) {
@@ -180,7 +180,7 @@ func TestWatch(t *testing.T) {
// Test-4: error happens on Watch, watch should stop // Test-4: error happens on Watch, watch should stop
// and error shall be returned. // and error shall be returned.
mcWatchMock = func(ctx context.Context, params mc.WatchOptions) (*mc.WatchObject, *probe.Error) { mcWatchMock = func(_ context.Context, _ mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
return nil, &probe.Error{Cause: fmt.Errorf("error on watch")} return nil, &probe.Error{Cause: fmt.Errorf("error on watch")}
} }
if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) { if err := startWatch(ctx, mockWSConn, client, testOptions); assert.Error(err) {
@@ -188,7 +188,7 @@ func TestWatch(t *testing.T) {
} }
// Test-5: return nil on error on watch // Test-5: return nil on error on watch
mcWatchMock = func(ctx context.Context, params mc.WatchOptions) (*mc.WatchObject, *probe.Error) { mcWatchMock = func(_ context.Context, _ mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
wo := &mc.WatchObject{ wo := &mc.WatchObject{
EventInfoChan: make(chan []mc.EventInfo), EventInfoChan: make(chan []mc.EventInfo),
ErrorChan: make(chan *probe.Error), ErrorChan: make(chan *probe.Error),

View File

@@ -200,7 +200,6 @@ func ValidateEncodedStyles(encodedStyles string) error {
var styleElements *CustomStyles var styleElements *CustomStyles
err = json.Unmarshal(str, &styleElements) err = json.Unmarshal(str, &styleElements)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -85,7 +85,7 @@ func TestRandomCharStringWithAlphabet(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, RandomCharStringWithAlphabet(tt.args.n, tt.args.alphabet), "RandomCharStringWithAlphabet(%v, %v)", tt.args.n, tt.args.alphabet) assert.Equalf(t, tt.want, RandomCharStringWithAlphabet(tt.args.n, tt.args.alphabet), "RandomCharStringWithAlphabet(%v, %v)", tt.args.n, tt.args.alphabet)
}) })
} }
@@ -117,7 +117,7 @@ func TestNewSessionCookieForConsole(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got := NewSessionCookieForConsole(tt.args.token) got := NewSessionCookieForConsole(tt.args.token)
assert.Equalf(t, tt.want.Value, got.Value, "NewSessionCookieForConsole(%v)", tt.args.token) assert.Equalf(t, tt.want.Value, got.Value, "NewSessionCookieForConsole(%v)", tt.args.token)
assert.Equalf(t, tt.want.Path, got.Path, "NewSessionCookieForConsole(%v)", tt.args.token) assert.Equalf(t, tt.want.Path, got.Path, "NewSessionCookieForConsole(%v)", tt.args.token)
@@ -144,7 +144,7 @@ func TestExpireSessionCookie(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got := ExpireSessionCookie() got := ExpireSessionCookie()
assert.Equalf(t, tt.want.Name, got.Name, "ExpireSessionCookie()") assert.Equalf(t, tt.want.Name, got.Name, "ExpireSessionCookie()")
assert.Equalf(t, tt.want.Value, got.Value, "ExpireSessionCookie()") assert.Equalf(t, tt.want.Value, got.Value, "ExpireSessionCookie()")
@@ -178,7 +178,7 @@ func TestSanitizeEncodedPrefix(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, SanitizeEncodedPrefix(tt.args.rawPrefix), "SanitizeEncodedPrefix(%v)", tt.args.rawPrefix) assert.Equalf(t, tt.want, SanitizeEncodedPrefix(tt.args.rawPrefix), "SanitizeEncodedPrefix(%v)", tt.args.rawPrefix)
}) })
} }
@@ -209,7 +209,7 @@ func Test_isSafeToPreview(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, isSafeToPreview(tt.args.str), "isSafeToPreview(%v)", tt.args.str) assert.Equalf(t, tt.want, isSafeToPreview(tt.args.str), "isSafeToPreview(%v)", tt.args.str)
}) })
} }
@@ -239,7 +239,7 @@ func TestRandomCharString(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.wantLength, len(RandomCharString(tt.args.n)), "RandomCharString(%v)", tt.args.n) assert.Equalf(t, tt.wantLength, len(RandomCharString(tt.args.n)), "RandomCharString(%v)", tt.args.n)
}) })
} }
@@ -284,7 +284,7 @@ func TestValidateEncodedStyles(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.wantErr { if tt.wantErr {
assert.NotNilf(t, ValidateEncodedStyles(tt.args.encodedStyles), "Wanted an error") assert.NotNilf(t, ValidateEncodedStyles(tt.args.encodedStyles), "Wanted an error")
} else { } else {
@@ -312,7 +312,7 @@ func TestSanitizeEncodedPrefix1(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
assert.Equalf(t, tt.want, SanitizeEncodedPrefix(tt.args.rawPrefix), "SanitizeEncodedPrefix(%v)", tt.args.rawPrefix) assert.Equalf(t, tt.want, SanitizeEncodedPrefix(tt.args.rawPrefix), "SanitizeEncodedPrefix(%v)", tt.args.rawPrefix)
}) })
} }

View File

@@ -164,7 +164,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
// can't validate the proper Origin since we don't know the source domain, so we are going // can't validate the proper Origin since we don't know the source domain, so we are going
// to allow the connection to be upgraded in this case. // to allow the connection to be upgraded in this case.
if getSubPath() != "/" || getConsoleDevMode() { if getSubPath() != "/" || getConsoleDevMode() {
upgrader.CheckOrigin = func(r *http.Request) bool { upgrader.CheckOrigin = func(_ *http.Request) bool {
return true return true
} }
} }

View File

@@ -264,7 +264,6 @@ func (wsc *wsMinioClient) objectManager(session *models.Principal) {
} }
err = wsc.conn.writeMessage(websocket.TextMessage, jsonData) err = wsc.conn.writeMessage(websocket.TextMessage, jsonData)
if err != nil { if err != nil {
LogInfo("Error while writing the message", err) LogInfo("Error while writing the message", err)
return return

View File

@@ -105,7 +105,7 @@ func newApp(name string) *cli.App {
app.Commands = commands app.Commands = commands
app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`. app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`.
app.CustomAppHelpTemplate = consoleHelpTemplate app.CustomAppHelpTemplate = consoleHelpTemplate
app.CommandNotFound = func(ctx *cli.Context, command string) { app.CommandNotFound = func(_ *cli.Context, command string) {
console.Printf("%s is not a console sub-command. See console --help.\n", command) console.Printf("%s is not a console sub-command. See console --help.\n", command)
closestCommands := findClosestCommands(command) closestCommands := findClosestCommands(command)
if len(closestCommands) > 0 { if len(closestCommands) > 0 {

View File

@@ -77,7 +77,7 @@ func Test_AddAccessRuleAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -133,7 +133,7 @@ func Test_GetAccessRulesAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -184,7 +184,7 @@ func Test_DeleteAccessRuleAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }

View File

@@ -48,7 +48,7 @@ func Test_ConfigAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/configs", nil) request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/configs", nil)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
@@ -99,7 +99,7 @@ func Test_GetConfigAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -158,7 +158,7 @@ func Test_SetConfigAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -220,7 +220,7 @@ func Test_ResetConfigAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }

View File

@@ -65,7 +65,7 @@ func Test_AddGroupAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -130,7 +130,7 @@ func Test_GetGroupAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -175,7 +175,7 @@ func Test_ListGroupsAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -244,7 +244,7 @@ func Test_PutGroupsAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -321,7 +321,7 @@ func Test_DeleteGroupAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }

View File

@@ -86,7 +86,7 @@ func TestInspect(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
resp, err := Inspect(tt.args.volume, tt.args.file, tt.args.encrypt) resp, err := Inspect(tt.args.volume, tt.args.file, tt.args.encrypt)
if tt.expectedError { if tt.expectedError {
assert.Nil(err) assert.Nil(err)

View File

@@ -51,7 +51,6 @@ func TestObjectGet(t *testing.T) {
} }
bucketName := fmt.Sprintf("testbucket-%d", rand.Intn(1000-1)+1) bucketName := fmt.Sprintf("testbucket-%d", rand.Intn(1000-1)+1)
err = minioClient.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true}) err = minioClient.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@@ -128,7 +127,7 @@ func TestObjectGet(t *testing.T) {
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")), encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
bytesRange: "bytes=9-12", bytesRange: "bytes=9-12",
}, },
expectedStatus: 400, expectedStatus: 500,
expectedError: nil, expectedError: nil,
}, },
{ {
@@ -146,7 +145,7 @@ func TestObjectGet(t *testing.T) {
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")), encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
bytesRange: "bytes=12-16", bytesRange: "bytes=12-16",
}, },
expectedStatus: 400, expectedStatus: 500,
expectedError: nil, expectedError: nil,
}, },
{ {
@@ -163,13 +162,13 @@ func TestObjectGet(t *testing.T) {
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject")), encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject")),
versionID: "garble", versionID: "garble",
}, },
expectedStatus: 400, expectedStatus: 500,
expectedError: nil, expectedError: nil,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -264,7 +263,7 @@ func TestDownloadMultipleFiles(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
resp, err := downloadMultipleFiles(tt.args.bucketName, tt.args.objectLis) resp, err := downloadMultipleFiles(tt.args.bucketName, tt.args.objectLis)
if tt.expectedError { if tt.expectedError {
assert.Nil(err) assert.Nil(err)

View File

@@ -182,7 +182,7 @@ func Test_AddPolicyAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -296,7 +296,7 @@ func Test_SetPolicyAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -408,7 +408,7 @@ func Test_SetPolicyMultipleAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -463,7 +463,7 @@ func Test_ListPoliciesAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -536,7 +536,7 @@ func Test_GetPolicyAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -611,7 +611,7 @@ func Test_PolicyListUsersAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -690,7 +690,7 @@ func Test_PolicyListGroupsAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -769,7 +769,7 @@ func Test_DeletePolicyAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -837,7 +837,7 @@ func Test_GetAUserPolicyAPI(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }

View File

@@ -40,7 +40,7 @@ func TestStartProfiling(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
files := map[string]bool{ files := map[string]bool{
"profile-127.0.0.1:9000-goroutines.txt": false, "profile-127.0.0.1:9000-goroutines.txt": false,
"profile-127.0.0.1:9000-goroutines-before.txt": false, "profile-127.0.0.1:9000-goroutines-before.txt": false,

View File

@@ -183,7 +183,7 @@ func Test_ServiceAccountsAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
@@ -290,7 +290,7 @@ func TestCreateServiceAccountForUserWithCredentials(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 2. Create the service account for the user // 2. Create the service account for the user
createServiceAccountWithCredentialsResponse, createServiceAccountWithCredentialsResponse,
createServiceAccountWithCredentialsError := CreateServiceAccountForUserWithCredentials( createServiceAccountWithCredentialsError := CreateServiceAccountForUserWithCredentials(

View File

@@ -816,7 +816,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 3. Put Objects Legal Status // 3. Put Objects Legal Status
putResponse, putError := PutObjectsLegalholdStatus( putResponse, putError := PutObjectsLegalholdStatus(
bucketName, bucketName,
@@ -895,7 +895,7 @@ func TestGetBucketQuota(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
restResp, restErr := GetBucketQuota( restResp, restErr := GetBucketQuota(
tt.args.bucketName, tt.args.bucketName,
) )
@@ -951,7 +951,7 @@ func TestPutBucketQuota(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
restResp, restErr := PutBucketQuota( restResp, restErr := PutBucketQuota(
tt.args.bucketName, tt.args.bucketName,
true, // enabled true, // enabled
@@ -1010,7 +1010,7 @@ func TestListBucketEvents(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
restResp, restErr := ListBucketEvents( restResp, restErr := ListBucketEvents(
tt.args.bucketName, tt.args.bucketName,
) )
@@ -1118,7 +1118,7 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 4. Delete Objects Retention Status // 4. Delete Objects Retention Status
putResponse, putError := DeleteObjectsRetentionStatus( putResponse, putError := DeleteObjectsRetentionStatus(
bucketName, bucketName,
@@ -1175,7 +1175,7 @@ func TestBucketSetPolicy(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// Set Policy // Set Policy
restResp, restErr := BucketSetPolicy( restResp, restErr := BucketSetPolicy(
tt.args.bucketName, tt.args.bucketName,
@@ -1265,7 +1265,7 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 4. Restore Object to a selected version // 4. Restore Object to a selected version
restResp, restErr := RestoreObjectToASelectedVersion( restResp, restErr := RestoreObjectToASelectedVersion(
bucketName, bucketName,
@@ -1323,7 +1323,7 @@ func TestPutBucketsTags(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 2. Add a tag to the bucket // 2. Add a tag to the bucket
tags := make(map[string]string) tags := make(map[string]string)
tags["tag2"] = "tag2" tags["tag2"] = "tag2"
@@ -1396,7 +1396,7 @@ func TestGetsTheMetadataOfAnObject(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 3. Get the metadata from an object // 3. Get the metadata from an object
getRsp, getErr := GetsTheMetadataOfAnObject( getRsp, getErr := GetsTheMetadataOfAnObject(
bucketName, tt.args.prefix) bucketName, tt.args.prefix)
@@ -1482,7 +1482,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 3. Put Objects Legal Status // 3. Put Objects Legal Status
putResponse, putError := PutObjectsRetentionStatus( putResponse, putError := PutObjectsRetentionStatus(
bucketName, bucketName,
@@ -1565,7 +1565,7 @@ func TestShareObjectOnURL(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// 3. Share the object on a URL // 3. Share the object on a URL
shareResponse, shareError := SharesAnObjectOnAUrl(bucketName, tt.args.prefix, versionID, "604800s") shareResponse, shareError := SharesAnObjectOnAUrl(bucketName, tt.args.prefix, versionID, "604800s")
assert.Nil(shareError) assert.Nil(shareError)
@@ -2138,7 +2138,7 @@ func TestDeleteBucket(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
// Create bucket if needed for the test // Create bucket if needed for the test
if tt.args.createBucketName != "" { if tt.args.createBucketName != "" {
if err := minioClient.MakeBucket(context.Background(), tt.args.createBucketName, minio.MakeBucketOptions{}); err != nil { if err := minioClient.MakeBucket(context.Background(), tt.args.createBucketName, minio.MakeBucketOptions{}); err != nil {
@@ -2464,7 +2464,7 @@ func TestAddBucket(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if !setupBucket(tt.args.bucketName, false, nil, nil, nil, assert, tt.expectedStatus) { if !setupBucket(tt.args.bucketName, false, nil, nil, nil, assert, tt.expectedStatus) {
return return
} }

View File

@@ -893,7 +893,7 @@ func Test_GetUserPolicyAPI(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
client := &http.Client{ client := &http.Client{
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }

View File

@@ -61,7 +61,7 @@ func TestGenerateLoginURL(t *testing.T) {
oauth2Config: Oauth2configMock{}, oauth2Config: Oauth2configMock{},
} }
// Test-1 : GenerateLoginURL() generates URL correctly with provided state // Test-1 : GenerateLoginURL() generates URL correctly with provided state
oauth2ConfigAuthCodeURLMock = func(state string, opts ...oauth2.AuthCodeOption) string { oauth2ConfigAuthCodeURLMock = func(state string, _ ...oauth2.AuthCodeOption) string {
// Internally we are testing the private method getRandomStateWithHMAC, this function should always returns // Internally we are testing the private method getRandomStateWithHMAC, this function should always returns
// a non-empty string // a non-empty string
return state return state

View File

@@ -174,7 +174,7 @@ func TestInitializeLogger(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.setEnvVars != nil { if tt.setEnvVars != nil {
tt.setEnvVars() tt.setEnvVars()
} }
@@ -197,7 +197,7 @@ func TestEnableJSON(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
EnableJSON() EnableJSON()
if !IsJSON() { if !IsJSON() {
t.Errorf("EnableJSON() = %v, want %v", IsJSON(), true) t.Errorf("EnableJSON() = %v, want %v", IsJSON(), true)
@@ -215,7 +215,7 @@ func TestEnableQuiet(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
EnableQuiet() EnableQuiet()
if !IsQuiet() { if !IsQuiet() {
t.Errorf("EnableQuiet() = %v, want %v", IsQuiet(), true) t.Errorf("EnableQuiet() = %v, want %v", IsQuiet(), true)
@@ -233,7 +233,7 @@ func TestEnableAnonymous(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
EnableAnonymous() EnableAnonymous()
if !IsAnonymous() { if !IsAnonymous() {
t.Errorf("EnableAnonymous() = %v, want %v", IsAnonymous(), true) t.Errorf("EnableAnonymous() = %v, want %v", IsAnonymous(), true)

View File

@@ -43,7 +43,7 @@ func TestNewEntry(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := NewEntry(tt.args.deploymentID); got.DeploymentID != tt.want.DeploymentID { if got := NewEntry(tt.args.deploymentID); got.DeploymentID != tt.want.DeploymentID {
t.Errorf("NewEntry() = %v, want %v", got, tt.want) t.Errorf("NewEntry() = %v, want %v", got, tt.want)
} }
@@ -106,7 +106,7 @@ func TestNewEntry(t *testing.T) {
// }, // },
// } // }
// for _, tt := range tests { // for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) { // t.Run(tt.name, func(_ *testing.T) {
// if tt.preFunc != nil { // if tt.preFunc != nil {
// tt.preFunc() // tt.preFunc()
// } // }

View File

@@ -52,7 +52,7 @@ func Test_subnetBaseURL(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if tt.args.env != nil { if tt.args.env != nil {
for k, v := range tt.args.env { for k, v := range tt.args.env {
os.Setenv(k, v) os.Setenv(k, v)
@@ -102,7 +102,7 @@ func Test_subnetRegisterURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetRegisterURL(); got != tt.want { if got := subnetRegisterURL(); got != tt.want {
t.Errorf("subnetRegisterURL() = %v, want %v", got, tt.want) t.Errorf("subnetRegisterURL() = %v, want %v", got, tt.want)
} }
@@ -147,7 +147,7 @@ func Test_subnetLoginURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetLoginURL(); got != tt.want { if got := subnetLoginURL(); got != tt.want {
t.Errorf("subnetLoginURL() = %v, want %v", got, tt.want) t.Errorf("subnetLoginURL() = %v, want %v", got, tt.want)
} }
@@ -192,7 +192,7 @@ func Test_subnetOrgsURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetOrgsURL(); got != tt.want { if got := subnetOrgsURL(); got != tt.want {
t.Errorf("subnetOrgsURL() = %v, want %v", got, tt.want) t.Errorf("subnetOrgsURL() = %v, want %v", got, tt.want)
} }
@@ -237,7 +237,7 @@ func Test_subnetMFAURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetMFAURL(); got != tt.want { if got := subnetMFAURL(); got != tt.want {
t.Errorf("subnetMFAURL() = %v, want %v", got, tt.want) t.Errorf("subnetMFAURL() = %v, want %v", got, tt.want)
} }
@@ -282,7 +282,7 @@ func Test_subnetAPIKeyURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetAPIKeyURL(); got != tt.want { if got := subnetAPIKeyURL(); got != tt.want {
t.Errorf("subnetAPIKeyURL() = %v, want %v", got, tt.want) t.Errorf("subnetAPIKeyURL() = %v, want %v", got, tt.want)
} }
@@ -327,7 +327,7 @@ func TestLogWebhookURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := LogWebhookURL(); got != tt.want { if got := LogWebhookURL(); got != tt.want {
t.Errorf("LogWebhookURL() = %v, want %v", got, tt.want) t.Errorf("LogWebhookURL() = %v, want %v", got, tt.want)
} }
@@ -378,7 +378,7 @@ func TestUploadURL(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
} }
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := UploadURL(tt.args.uploadType, tt.args.filename); got != tt.want { if got := UploadURL(tt.args.uploadType, tt.args.filename); got != tt.want {
t.Errorf("UploadURL() = %v, want %v", got, tt.want) t.Errorf("UploadURL() = %v, want %v", got, tt.want)
} }
@@ -409,7 +409,7 @@ func TestUploadAuthHeaders(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := UploadAuthHeaders(tt.args.apiKey); !reflect.DeepEqual(got, tt.want) { if got := UploadAuthHeaders(tt.args.apiKey); !reflect.DeepEqual(got, tt.want) {
t.Errorf("UploadAuthHeaders() = %v, want %v", got, tt.want) t.Errorf("UploadAuthHeaders() = %v, want %v", got, tt.want)
} }
@@ -442,7 +442,7 @@ func TestGenerateRegToken(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, err := GenerateRegToken(tt.args.clusterRegInfo) got, err := GenerateRegToken(tt.args.clusterRegInfo)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GenerateRegToken() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GenerateRegToken() error = %v, wantErr %v", err, tt.wantErr)
@@ -473,7 +473,7 @@ func Test_subnetAuthHeaders(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := subnetAuthHeaders(tt.args.authToken); !reflect.DeepEqual(got, tt.want) { if got := subnetAuthHeaders(tt.args.authToken); !reflect.DeepEqual(got, tt.want) {
t.Errorf("subnetAuthHeaders() = %v, want %v", got, tt.want) t.Errorf("subnetAuthHeaders() = %v, want %v", got, tt.want)
} }
@@ -594,7 +594,7 @@ func Test_getDriveSpaceInfo(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, got1 := getDriveSpaceInfo(tt.args.admInfo) got, got1 := getDriveSpaceInfo(tt.args.admInfo)
if got != tt.want { if got != tt.want {
t.Errorf("getDriveSpaceInfo() got = %v, want %v", got, tt.want) t.Errorf("getDriveSpaceInfo() got = %v, want %v", got, tt.want)

View File

@@ -36,7 +36,7 @@ func TestGetDivisibleSize(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
testCase := testCase testCase := testCase
t.Run("", func(t *testing.T) { t.Run("", func(_ *testing.T) {
gotGCD := getDivisibleSize(testCase.totalSizes) gotGCD := getDivisibleSize(testCase.totalSizes)
if testCase.result != gotGCD { if testCase.result != gotGCD {
t.Errorf("Expected %v, got %v", testCase.result, gotGCD) t.Errorf("Expected %v, got %v", testCase.result, gotGCD)
@@ -143,7 +143,7 @@ func TestGetSetIndexes(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
testCase := testCase testCase := testCase
t.Run("", func(t *testing.T) { t.Run("", func(_ *testing.T) {
argPatterns := make([]ellipses.ArgPattern, len(testCase.args)) argPatterns := make([]ellipses.ArgPattern, len(testCase.args))
for i, arg := range testCase.args { for i, arg := range testCase.args {
patterns, err := ellipses.FindEllipsesPatterns(arg) patterns, err := ellipses.FindEllipsesPatterns(arg)
@@ -277,7 +277,7 @@ func TestPossibleParities(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
testCase := testCase testCase := testCase
t.Run("", func(t *testing.T) { t.Run("", func(_ *testing.T) {
gotPs, err := PossibleParityValues(testCase.arg) gotPs, err := PossibleParityValues(testCase.arg)
if err != nil && testCase.success { if err != nil && testCase.success {
t.Errorf("Expected success but failed instead %s", err) t.Errorf("Expected success but failed instead %s", err)

View File

@@ -81,7 +81,7 @@ func TestDecodeInput(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
got, err := DecodeBase64(tt.args.s) got, err := DecodeBase64(tt.args.s)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("DecodeBase64() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DecodeBase64() error = %v, wantErr %v", err, tt.wantErr)
@@ -119,7 +119,7 @@ func TestClientIPFromContext(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
if got := ClientIPFromContext(tt.args.ctx); got != tt.want { if got := ClientIPFromContext(tt.args.ctx); got != tt.want {
t.Errorf("ClientIPFromContext() = %v, want %v", got, tt.want) t.Errorf("ClientIPFromContext() = %v, want %v", got, tt.want)
} }

View File

@@ -204,7 +204,7 @@ func TestAddSiteReplicationInfo(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
actualStatusCode, err := AddSiteReplicationInfo(tt.args.sites) actualStatusCode, err := AddSiteReplicationInfo(tt.args.sites)
fmt.Println("TestAddSiteReplicationInfo: ", actualStatusCode) fmt.Println("TestAddSiteReplicationInfo: ", actualStatusCode)
@@ -269,7 +269,7 @@ func TestEditSiteReplicationInfo(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
actualStatusCode, err := EditSiteReplicationInfo(tt.args) actualStatusCode, err := EditSiteReplicationInfo(tt.args)
fmt.Println("TestEditSiteReplicationInfo: ", actualStatusCode) fmt.Println("TestEditSiteReplicationInfo: ", actualStatusCode)
if tt.expStatusCode > 0 { if tt.expStatusCode > 0 {
@@ -331,7 +331,7 @@ func TestDeleteSiteReplicationInfo(t *testing.T) {
} }
fmt.Println("Delete Site Replication") fmt.Println("Delete Site Replication")
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
actualStatusCode, err := DeleteSiteReplicationInfo(tt.args) actualStatusCode, err := DeleteSiteReplicationInfo(tt.args)
fmt.Println("TestDeleteSiteReplicationInfo: ", actualStatusCode) fmt.Println("TestDeleteSiteReplicationInfo: ", actualStatusCode)
if tt.expStatusCode > 0 { if tt.expStatusCode > 0 {
@@ -440,7 +440,7 @@ func TestGetSiteReplicationStatus(t *testing.T) {
} }
for ti, tt := range tests { for ti, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(_ *testing.T) {
response, err := makeStatusExecuteReq("GET", tt.args) response, err := makeStatusExecuteReq("GET", tt.args)
tgt := &models.SiteReplicationStatusResponse{} tgt := &models.SiteReplicationStatusResponse{}
json.NewDecoder(response.Body).Decode(tgt) json.NewDecoder(response.Body).Decode(tgt)

View File

@@ -135,7 +135,6 @@ func TestMain(t *testing.T) {
fmt.Println(body) fmt.Println(body)
err = json.Unmarshal(body, &jsonMap) err = json.Unmarshal(body, &jsonMap)
if err != nil { if err != nil {
fmt.Printf("error JSON Unmarshal %s\n", err) fmt.Printf("error JSON Unmarshal %s\n", err)
} }