Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5423d9d7f |
+38
-33
@@ -1188,47 +1188,52 @@ func TestFetchRefusesListedManifestName(t *testing.T) {
|
|||||||
// .a.txt.tmp, the temp file fetch downloads a.txt to, at the top of the
|
// .a.txt.tmp, the temp file fetch downloads a.txt to, at the top of the
|
||||||
// tree and in a directory. Downloading a.txt would remove .a.txt.tmp, so
|
// tree and in a directory. Downloading a.txt would remove .a.txt.tmp, so
|
||||||
// fetch must refuse the manifest before it creates the destination or
|
// fetch must refuse the manifest before it creates the destination or
|
||||||
// requests any file. A manifest that lists only one of the two is fetched
|
// requests any file. README with .README.tmp checks that temp names are
|
||||||
// in full.
|
// compared ignoring case. A manifest that lists only one of the two is
|
||||||
|
// fetched in full.
|
||||||
func TestFetchRefusesListedTempName(t *testing.T) {
|
func TestFetchRefusesListedTempName(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
for _, dir := range []string{"", "sub/"} {
|
for _, dir := range []string{"", "sub/"} {
|
||||||
file, tmp := dir+"a.txt", dir+".a.txt.tmp"
|
for file, tmp := range map[string]string{
|
||||||
both := map[string][]byte{
|
dir + "a.txt": dir + ".a.txt.tmp",
|
||||||
file: []byte("a file"),
|
dir + "README": dir + ".README.tmp",
|
||||||
tmp: []byte("a file at its temp name"),
|
} {
|
||||||
}
|
both := map[string][]byte{
|
||||||
|
file: []byte("a file"),
|
||||||
|
tmp: []byte("a file at its temp name"),
|
||||||
|
}
|
||||||
|
|
||||||
t.Run(file+" and "+tmp, func(t *testing.T) {
|
t.Run(file+" and "+tmp, func(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
assertFetchRefused(t, builtManifest(t, both), both,
|
|
||||||
"manifest lists a file where fetch writes another file: "+
|
|
||||||
tmp+" (the temp file for "+file+")")
|
|
||||||
})
|
|
||||||
|
|
||||||
for listed, content := range both {
|
|
||||||
t.Run("only "+listed, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
files := map[string][]byte{listed: content}
|
assertFetchRefused(t, builtManifest(t, both), both,
|
||||||
manifest := builtManifest(t, files)
|
"manifest lists a file where fetch writes another file: "+
|
||||||
|
tmp+" (the temp file for "+file+")")
|
||||||
server := httptest.NewServer(fetchTestHandler(manifest, files))
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
dest := t.TempDir()
|
|
||||||
|
|
||||||
opts := testOpts([]string{
|
|
||||||
testApp, cmdFetch, "-q", "--" + flagDest, dest, server.URL,
|
|
||||||
}, afero.NewOsFs())
|
|
||||||
require.Equal(t, 0, runCLI(opts), testStderr(t, opts))
|
|
||||||
|
|
||||||
want := maps.Clone(files)
|
|
||||||
want[defaultManifestName] = manifest
|
|
||||||
assert.Equal(t, want, filesUnder(t, dest))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for listed, content := range both {
|
||||||
|
t.Run("only "+listed, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := map[string][]byte{listed: content}
|
||||||
|
manifest := builtManifest(t, files)
|
||||||
|
|
||||||
|
server := httptest.NewServer(fetchTestHandler(manifest, files))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
dest := t.TempDir()
|
||||||
|
|
||||||
|
opts := testOpts([]string{
|
||||||
|
testApp, cmdFetch, "-q", "--" + flagDest, dest, server.URL,
|
||||||
|
}, afero.NewOsFs())
|
||||||
|
require.Equal(t, 0, runCLI(opts), testStderr(t, opts))
|
||||||
|
|
||||||
|
want := maps.Clone(files)
|
||||||
|
want[defaultManifestName] = manifest
|
||||||
|
assert.Equal(t, want, filesUnder(t, dest))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user