Skip to content

Commit 8ac1737

Browse files
committed
move exec_wrapper to another common directory
1 parent 40fa19a commit 8ac1737

6 files changed

Lines changed: 20 additions & 19 deletions

File tree

pkg/perf/cpubench/cpubench_task.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"fmt"
77

88
"github.com/threefoldtech/zosbase/pkg/perf"
9-
"github.com/threefoldtech/zosbase/pkg/perf/iperf" // Import for ExecWrapper
9+
execwrapper "github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
1010
"github.com/threefoldtech/zosbase/pkg/stubs"
1111
)
1212

1313
// CPUBenchmarkTask defines CPU benchmark task.
1414
type CPUBenchmarkTask struct {
15-
execWrapper iperf.ExecWrapper
15+
execWrapper execwrapper.ExecWrapper
1616
}
1717

1818
// CPUBenchmarkResult holds CPU benchmark results with the workloads number during the benchmark.
@@ -28,11 +28,11 @@ var _ perf.Task = (*CPUBenchmarkTask)(nil)
2828
// NewTask returns a new CPU benchmark task.
2929
func NewTask() perf.Task {
3030
return &CPUBenchmarkTask{
31-
execWrapper: &iperf.RealExecWrapper{},
31+
execWrapper: &execwrapper.RealExecWrapper{},
3232
}
3333
}
3434

35-
func NewTaskWithExecWrapper(execWrapper iperf.ExecWrapper) perf.Task {
35+
func NewTaskWithExecWrapper(execWrapper execwrapper.ExecWrapper) perf.Task {
3636
return &CPUBenchmarkTask{
3737
execWrapper: execWrapper,
3838
}

pkg/perf/cpubench/cpubench_task_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/threefoldtech/zbus"
1212
"github.com/threefoldtech/zosbase/pkg/mocks"
1313
"github.com/threefoldtech/zosbase/pkg/perf"
14-
"github.com/threefoldtech/zosbase/pkg/perf/iperf"
14+
execwrapper "github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
1515
"go.uber.org/mock/gomock"
1616
)
1717

@@ -35,8 +35,8 @@ func TestCPUBenchmarkTask_Run(t *testing.T) {
3535
ctrl := gomock.NewController(t)
3636
defer ctrl.Finish()
3737

38-
mockExec := iperf.NewMockExecWrapper(ctrl)
39-
mockCmd := iperf.NewMockExecCmd(ctrl)
38+
mockExec := execwrapper.NewMockExecWrapper(ctrl)
39+
mockCmd := execwrapper.NewMockExecCmd(ctrl)
4040
task := NewTaskWithExecWrapper(mockExec).(*CPUBenchmarkTask)
4141
ctx := context.Background()
4242
mockZbus := mocks.NewMockClient(ctrl)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package iperf
1+
package execwrapper
22

33
import (
44
"context"

pkg/perf/iperf/mock_exec_wrapper.go renamed to pkg/perf/exec_wrapper/mock_exec_wrapper.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/perf/iperf/iperf_task.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/threefoldtech/zosbase/pkg/environment"
1717
"github.com/threefoldtech/zosbase/pkg/network/iperf"
1818
"github.com/threefoldtech/zosbase/pkg/perf"
19+
"github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
1920
"github.com/threefoldtech/zosbase/pkg/perf/graphql"
2021
)
2122

@@ -32,7 +33,7 @@ const (
3233
type IperfTest struct {
3334
// Optional dependencies for testing
3435
graphqlClient GraphQLClient
35-
execWrapper ExecWrapper
36+
execWrapper execwrapper.ExecWrapper
3637
}
3738

3839
// IperfResult for iperf test results
@@ -170,7 +171,7 @@ func (t *IperfTest) runIperfTest(ctx context.Context, clientIP string, tcp bool)
170171
opts = append(opts, "--length", "16B", "--udp")
171172
}
172173

173-
execWrap := execWrapper
174+
var execWrap execwrapper.ExecWrapper = &execwrapper.RealExecWrapper{}
174175
if t.execWrapper != nil {
175176
execWrap = t.execWrapper
176177
}
@@ -221,7 +222,7 @@ func (t *IperfTest) runIperfTest(ctx context.Context, clientIP string, tcp bool)
221222
return iperfResult
222223
}
223224

224-
func runIperfCommand(ctx context.Context, opts []string, execWrap ExecWrapper) iperfCommandOutput {
225+
func runIperfCommand(ctx context.Context, opts []string, execWrap execwrapper.ExecWrapper) iperfCommandOutput {
225226
output, err := execWrap.CommandContext(ctx, "iperf", opts...).CombinedOutput()
226227
exitErr := &exec.ExitError{}
227228
if err != nil && !errors.As(err, &exitErr) {

pkg/perf/iperf/iperf_task_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
execwrapper "github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
1011
"github.com/threefoldtech/zosbase/pkg/perf/graphql"
1112
"go.uber.org/mock/gomock"
1213
)
@@ -16,8 +17,8 @@ func TestIperfTest_Run_Success(t *testing.T) {
1617
defer ctrl.Finish()
1718

1819
mockGraphQL := NewMockGraphQLClient(ctrl)
19-
mockExec := NewMockExecWrapper(ctrl)
20-
mockCmd := NewMockExecCmd(ctrl)
20+
mockExec := execwrapper.NewMockExecWrapper(ctrl)
21+
mockCmd := execwrapper.NewMockExecCmd(ctrl)
2122

2223
task := &IperfTest{
2324
graphqlClient: mockGraphQL,
@@ -111,7 +112,7 @@ func TestIperfTest_Run_IperfNotFound(t *testing.T) {
111112
defer ctrl.Finish()
112113

113114
mockGraphQL := NewMockGraphQLClient(ctrl)
114-
mockExec := NewMockExecWrapper(ctrl)
115+
mockExec := execwrapper.NewMockExecWrapper(ctrl)
115116

116117
task := &IperfTest{
117118
graphqlClient: mockGraphQL,
@@ -142,7 +143,7 @@ func TestIperfTest_Run_InvalidIPAddress(t *testing.T) {
142143
defer ctrl.Finish()
143144

144145
mockGraphQL := NewMockGraphQLClient(ctrl)
145-
mockExec := NewMockExecWrapper(ctrl)
146+
mockExec := execwrapper.NewMockExecWrapper(ctrl)
146147

147148
task := &IperfTest{
148149
graphqlClient: mockGraphQL,

0 commit comments

Comments
 (0)