|
|
@ -18,6 +18,8 @@ package api |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
// "encoding/json"
|
|
|
|
// "encoding/json"
|
|
|
|
|
|
|
|
"bytes" |
|
|
|
|
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -78,3 +80,34 @@ func TestGetEntry(t *testing.T) { |
|
|
|
func TestDeleteEntry(t *testing.T) { |
|
|
|
func TestDeleteEntry(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TestAddFileWithManifestPath tests that adding an entry at a path which
|
|
|
|
|
|
|
|
// already exists as a manifest just adds the entry to the manifest rather
|
|
|
|
|
|
|
|
// than replacing the manifest with the entry
|
|
|
|
|
|
|
|
func TestAddFileWithManifestPath(t *testing.T) { |
|
|
|
|
|
|
|
// create a manifest containing "ab" and "ac"
|
|
|
|
|
|
|
|
manifest, _ := json.Marshal(&Manifest{ |
|
|
|
|
|
|
|
Entries: []ManifestEntry{ |
|
|
|
|
|
|
|
{Path: "ab", Hash: "ab"}, |
|
|
|
|
|
|
|
{Path: "ac", Hash: "ac"}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
reader := &storage.LazyTestSectionReader{ |
|
|
|
|
|
|
|
SectionReader: io.NewSectionReader(bytes.NewReader(manifest), 0, int64(len(manifest))), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
trie, err := readManifest(reader, nil, nil, nil) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
checkEntry(t, "ab", "ab", trie) |
|
|
|
|
|
|
|
checkEntry(t, "ac", "ac", trie) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// now add path "a" and check we can still get "ab" and "ac"
|
|
|
|
|
|
|
|
entry := &manifestTrieEntry{} |
|
|
|
|
|
|
|
entry.Path = "a" |
|
|
|
|
|
|
|
entry.Hash = "a" |
|
|
|
|
|
|
|
trie.addEntry(entry, nil) |
|
|
|
|
|
|
|
checkEntry(t, "ab", "ab", trie) |
|
|
|
|
|
|
|
checkEntry(t, "ac", "ac", trie) |
|
|
|
|
|
|
|
checkEntry(t, "a", "a", trie) |
|
|
|
|
|
|
|
} |
|
|
|