hex-encoding Test that we can pk-put and pk-get a file whose name is not utf8, that we don't panic in the process and that the results are correct.
(t *testing.T)
| 35 | // that we don't panic in the process and that the results are |
| 36 | // correct. |
| 37 | func TestNonUTF8FileName(t *testing.T) { |
| 38 | srcDir := t.TempDir() |
| 39 | |
| 40 | base, err := hex.DecodeString(nonUTF8) |
| 41 | if err != nil { |
| 42 | t.Fatalf("hex.DecodeString(): %v", err) |
| 43 | } |
| 44 | |
| 45 | fd, err := os.Create(filepath.Join(srcDir, string(base))) |
| 46 | if isBadFilenameError(err) { |
| 47 | // TODO: decide how we want to handle this in the future. |
| 48 | // Normalize to UTF-8 with heuristics in pk-get? |
| 49 | t.Skip("skipping non-UTF-8 test on system requiring UTF-8") |
| 50 | } |
| 51 | if err != nil { |
| 52 | t.Fatalf("os.Create(): %v", err) |
| 53 | } |
| 54 | fd.Close() |
| 55 | |
| 56 | w := test.GetWorld(t) |
| 57 | out := test.MustRunCmd(t, w.Cmd("pk-put", "file", fd.Name())) |
| 58 | br := strings.Split(out, "\n")[0] |
| 59 | |
| 60 | // pk-put was a success. Can we get the file back in another directory? |
| 61 | dstDir := t.TempDir() |
| 62 | |
| 63 | _ = test.MustRunCmd(t, w.Cmd("pk-get", "-o", dstDir, br)) |
| 64 | _, err = os.Lstat(filepath.Join(dstDir, string(base))) |
| 65 | if err != nil { |
| 66 | t.Fatalf("Failed to stat file %s in directory %s", |
| 67 | fd.Name(), dstDir) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Test that we can pk-put and pk-get a symbolic link whose target is |
| 72 | // not utf8, that we do no panic in the process and that the results |
nothing calls this directly
no test coverage detected