Skip to content

Commit 12fa99c

Browse files
author
anencore94
committed
[Enhancement] Add functional test for scp command
- skip tests for windows os Signed-off-by: anencore94 <anencore94@kaist.ac.kr>
1 parent 1a3a80d commit 12fa99c

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

cmd/minikube/cmd/scp.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222
"path/filepath"
2323

2424
"github.com/spf13/cobra"
25+
2526
"k8s.io/minikube/pkg/minikube/config"
2627
"k8s.io/minikube/pkg/minikube/exit"
2728
"k8s.io/minikube/pkg/minikube/localpath"
2829
"k8s.io/minikube/pkg/minikube/mustload"
2930
"k8s.io/minikube/pkg/minikube/node"
3031
"k8s.io/minikube/pkg/minikube/out"
32+
3133
"k8s.io/minikube/pkg/minikube/reason"
3234
)
3335

@@ -45,7 +47,7 @@ var (
4547
var scpCmd = &cobra.Command{
4648
Use: "scp [flags] <source file or directory path> <target file or directory path followed by '/home/docker/'>",
4749
Short: "Copy the specified file or directory into minikube",
48-
Long: "Copy the specified file or directory into minikube, it will be saved at path \"/home/docker/<target file or directory path>\" in your minikube.\n" +
50+
Long: "Copy the specified file or directory into minikube, it will be saved at path \"/home/docker/<target file or directory path>\" in your minikube.\n" +
4951
"Example Command : \"minikube scp a.txt b.txt\"\n",
5052
Run: func(cmd *cobra.Command, args []string) {
5153
// validate args

site/content/en/docs/commands/scp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ minikube scp [flags] <source file or directory path> <target file or directory p
3636
--skip_headers If true, avoid header prefixes in the log messages
3737
--skip_log_headers If true, avoid headers when opening log files
3838
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
39+
--user string Specifies the user executing the operation. Useful for auditing operations executed by 3rd party tools. Defaults to the operating system username.
3940
-v, --v Level number for the log level verbosity
4041
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
4142
```

test/integration/functional_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestFunctional(t *testing.T) {
121121
{"PersistentVolumeClaim", validatePersistentVolumeClaim},
122122
{"TunnelCmd", validateTunnelCmd},
123123
{"SSHCmd", validateSSHCmd},
124+
{"ScpCmd", validateScpCmd},
124125
{"MySQL", validateMySQL},
125126
{"FileSync", validateFileSync},
126127
{"CertSync", validateCertSync},
@@ -1117,6 +1118,37 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
11171118
}
11181119
}
11191120

1121+
// validateScpCmd asserts basic "scp" command functionality
1122+
func validateScpCmd(ctx context.Context, t *testing.T, profile string) {
1123+
if windowsPlatform() {
1124+
t.Skipf("skipping: scp is unsupported by windows os")
1125+
}
1126+
if NoneDriver() {
1127+
t.Skipf("skipping: scp is unsupported by none driver")
1128+
}
1129+
1130+
scpPath := filepath.Join(*testdataDir, "scp-test.txt")
1131+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "scp", scpPath, "hello_scp.txt"))
1132+
if ctx.Err() == context.DeadlineExceeded {
1133+
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
1134+
}
1135+
if err != nil {
1136+
t.Errorf("failed to run an scp command. args %q : %v", rr.Command(), err)
1137+
}
1138+
1139+
expected := "Test file for checking file scp process"
1140+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat hello_scp.txt"))
1141+
if ctx.Err() == context.DeadlineExceeded {
1142+
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
1143+
}
1144+
if err != nil {
1145+
t.Errorf("failed to run an scp command. args %q : %v", rr.Command(), err)
1146+
}
1147+
if diff := cmp.Diff(expected, rr.Stdout.String()); diff != "" {
1148+
t.Errorf("/testdata/scp-test.txt content mismatch (-want +got):\n%s", diff)
1149+
}
1150+
}
1151+
11201152
// validateMySQL validates a minimalist MySQL deployment
11211153
func validateMySQL(ctx context.Context, t *testing.T, profile string) {
11221154
if arm64Platform() {

test/integration/main_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func arm64Platform() bool {
157157
return runtime.GOARCH == "arm64"
158158
}
159159

160+
// windowsPlatform returns true if running on windows platform
161+
func windowsPlatform() bool {
162+
return runtime.GOARCH == "windows"
163+
}
164+
160165
// NeedsPortForward returns access to endpoints with this driver needs port forwarding
161166
// (Docker on non-Linux platforms requires ports to be forwarded to 127.0.0.1)
162167
func NeedsPortForward() bool {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test file for checking file scp process

0 commit comments

Comments
 (0)