(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestSFTPOptions(t *testing.T) { |
| 18 | td := t.TempDir() |
| 19 | |
| 20 | myKeyFile := filepath.Join(td, "my-key") |
| 21 | myKnownHostsFile := filepath.Join(td, "my-known-hosts") |
| 22 | |
| 23 | require.NoError(t, os.WriteFile(myKeyFile, []byte("fake-key-data"), 0o600)) |
| 24 | require.NoError(t, os.WriteFile(myKnownHostsFile, []byte("fake-known-hosts-data"), 0o600)) |
| 25 | |
| 26 | cases := []struct { |
| 27 | input storageSFTPFlags |
| 28 | want *sftp.Options |
| 29 | wantErr string |
| 30 | }{ |
| 31 | // 0 |
| 32 | { |
| 33 | input: storageSFTPFlags{ |
| 34 | options: sftp.Options{ |
| 35 | Host: "some-host", |
| 36 | Port: 222, |
| 37 | Username: "user", |
| 38 | KnownHostsFile: "my-known-hosts", |
| 39 | Keyfile: "my-key", |
| 40 | }, |
| 41 | }, |
| 42 | want: &sftp.Options{ |
| 43 | Host: "some-host", |
| 44 | Port: 222, |
| 45 | Username: "user", |
| 46 | KnownHostsFile: mustFileAbs(t, "my-known-hosts"), |
| 47 | Keyfile: mustFileAbs(t, "my-key"), |
| 48 | }, |
| 49 | }, |
| 50 | // 1 |
| 51 | { |
| 52 | input: storageSFTPFlags{ |
| 53 | options: sftp.Options{ |
| 54 | Host: "some-host", |
| 55 | Port: 222, |
| 56 | Username: "user", |
| 57 | Keyfile: "no-such-file", |
| 58 | KnownHostsFile: myKnownHostsFile, |
| 59 | }, |
| 60 | embedCredentials: true, |
| 61 | }, |
| 62 | wantErr: "unable to read key file", |
| 63 | }, |
| 64 | // 2 |
| 65 | { |
| 66 | input: storageSFTPFlags{ |
| 67 | options: sftp.Options{ |
| 68 | Host: "some-host", |
| 69 | Port: 222, |
| 70 | Username: "user", |
| 71 | Keyfile: myKeyFile, |
| 72 | KnownHostsFile: "no-such-file", |
| 73 | }, |
| 74 | embedCredentials: true, |
nothing calls this directly
no test coverage detected
searching dependent graphs…