Skip to content

Commit

Permalink
[Enhancement] Add functional test for scp command
Browse files Browse the repository at this point in the history
Signed-off-by: anencore94 <anencore94@kaist.ac.kr>
  • Loading branch information
anencore94 committed Feb 16, 2021
1 parent e7a02f2 commit 5719576
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/minikube/cmd/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
"path/filepath"

"github.com/spf13/cobra"

"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"

"k8s.io/minikube/pkg/minikube/reason"
)

Expand All @@ -45,7 +47,7 @@ var (
var scpCmd = &cobra.Command{
Use: "scp [flags] <source file or directory path> <target file or directory path followed by '/home/docker/'>",
Short: "Copy the specified file or directory into minikube",
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" +
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" +
"Example Command : \"minikube scp a.txt b.txt\"\n",
Run: func(cmd *cobra.Command, args []string) {
// validate args
Expand Down
29 changes: 29 additions & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestFunctional(t *testing.T) {
{"PersistentVolumeClaim", validatePersistentVolumeClaim},
{"TunnelCmd", validateTunnelCmd},
{"SSHCmd", validateSSHCmd},
{"ScpCmd", validateScpCmd},
{"MySQL", validateMySQL},
{"FileSync", validateFileSync},
{"CertSync", validateCertSync},
Expand Down Expand Up @@ -981,6 +982,34 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
}
}

// validateScpCmd asserts basic "scp" command functionality
func validateScpCmd(ctx context.Context, t *testing.T, profile string) {
if NoneDriver() {
t.Skipf("skipping: scp unsupported by none")
}

scpPath := filepath.Join(*testdataDir, "scp.test")
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "scp", scpPath, "hello_scp.txt"))
if ctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}
if err != nil {
t.Errorf("failed to run an scp command. args %q : %v", rr.Command(), err)
}

expected := "Test file for checking file scp process"
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat hello_scp.txt"))
if ctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}
if err != nil {
t.Errorf("failed to run an scp command. args %q : %v", rr.Command(), err)
}
if diff := cmp.Diff(expected, rr.Stdout.String()); diff != "" {
t.Errorf("/testdata/scp.test content mismatch (-want +got):\n%s", diff)
}
}

// validateMySQL validates a minimalist MySQL deployment
func validateMySQL(ctx context.Context, t *testing.T, profile string) {
if arm64Platform() {
Expand Down

0 comments on commit 5719576

Please sign in to comment.