github.com/mckael/restic@v0.8.3/internal/backend/sftp/sshcmd_test.go (about)

     1  package sftp
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  var sshcmdTests = []struct {
     9  	cfg  Config
    10  	cmd  string
    11  	args []string
    12  }{
    13  	{
    14  		Config{User: "user", Host: "host", Path: "dir/subdir"},
    15  		"ssh",
    16  		[]string{"host", "-l", "user", "-s", "sftp"},
    17  	},
    18  	{
    19  		Config{Host: "host", Path: "dir/subdir"},
    20  		"ssh",
    21  		[]string{"host", "-s", "sftp"},
    22  	},
    23  	{
    24  		Config{Host: "host:10022", Path: "/dir/subdir"},
    25  		"ssh",
    26  		[]string{"host", "-p", "10022", "-s", "sftp"},
    27  	},
    28  	{
    29  		Config{User: "user", Host: "host:10022", Path: "/dir/subdir"},
    30  		"ssh",
    31  		[]string{"host", "-p", "10022", "-l", "user", "-s", "sftp"},
    32  	},
    33  }
    34  
    35  func TestBuildSSHCommand(t *testing.T) {
    36  	for _, test := range sshcmdTests {
    37  		t.Run("", func(t *testing.T) {
    38  			cmd, args, err := buildSSHCommand(test.cfg)
    39  			if err != nil {
    40  				t.Fatal(err)
    41  			}
    42  
    43  			if cmd != test.cmd {
    44  				t.Fatalf("cmd: want %v, got %v", test.cmd, cmd)
    45  			}
    46  
    47  			if !reflect.DeepEqual(test.args, args) {
    48  				t.Fatalf("wrong args, want:\n  %v\ngot:\n  %v", test.args, args)
    49  			}
    50  		})
    51  	}
    52  }