2018-05-13 13:28:09 +00:00
|
|
|
/*
|
2019-03-20 19:32:48 +00:00
|
|
|
Copyright 2018 the Velero contributors.
|
2018-05-13 13:28:09 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
2023-03-24 04:15:08 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2018-05-13 13:28:09 +00:00
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2018-02-28 01:35:35 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
|
2019-09-30 21:26:56 +00:00
|
|
|
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
2018-02-28 01:35:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MockPodCommandExecutor struct {
|
|
|
|
mock.Mock
|
2024-08-05 14:53:51 +00:00
|
|
|
// hook execution order
|
|
|
|
HookExecutionLog []HookExecutionEntry
|
|
|
|
}
|
|
|
|
|
|
|
|
type HookExecutionEntry struct {
|
|
|
|
Namespace, Name, HookName string
|
|
|
|
HookCommand []string
|
2018-02-28 01:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *MockPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *v1.ExecHook) error {
|
2024-08-05 14:53:51 +00:00
|
|
|
e.HookExecutionLog = append(e.HookExecutionLog, HookExecutionEntry{
|
|
|
|
Namespace: namespace,
|
|
|
|
Name: name,
|
|
|
|
HookName: hookName,
|
|
|
|
HookCommand: hook.Command,
|
|
|
|
})
|
2018-02-28 01:35:35 +00:00
|
|
|
args := e.Called(log, item, namespace, name, hookName, hook)
|
|
|
|
return args.Error(0)
|
|
|
|
}
|