@@ -18,6 +18,8 @@ package api
18
18
19
19
import (
20
20
// "encoding/json"
21
+ "bytes"
22
+ "encoding/json"
21
23
"fmt"
22
24
"io"
23
25
"strings"
@@ -78,3 +80,34 @@ func TestGetEntry(t *testing.T) {
78
80
func TestDeleteEntry (t * testing.T ) {
79
81
80
82
}
83
+
84
+ // TestAddFileWithManifestPath tests that adding an entry at a path which
85
+ // already exists as a manifest just adds the entry to the manifest rather
86
+ // than replacing the manifest with the entry
87
+ func TestAddFileWithManifestPath (t * testing.T ) {
88
+ // create a manifest containing "ab" and "ac"
89
+ manifest , _ := json .Marshal (& Manifest {
90
+ Entries : []ManifestEntry {
91
+ {Path : "ab" , Hash : "ab" },
92
+ {Path : "ac" , Hash : "ac" },
93
+ },
94
+ })
95
+ reader := & storage.LazyTestSectionReader {
96
+ SectionReader : io .NewSectionReader (bytes .NewReader (manifest ), 0 , int64 (len (manifest ))),
97
+ }
98
+ trie , err := readManifest (reader , nil , nil , nil )
99
+ if err != nil {
100
+ t .Fatal (err )
101
+ }
102
+ checkEntry (t , "ab" , "ab" , trie )
103
+ checkEntry (t , "ac" , "ac" , trie )
104
+
105
+ // now add path "a" and check we can still get "ab" and "ac"
106
+ entry := & manifestTrieEntry {}
107
+ entry .Path = "a"
108
+ entry .Hash = "a"
109
+ trie .addEntry (entry , nil )
110
+ checkEntry (t , "ab" , "ab" , trie )
111
+ checkEntry (t , "ac" , "ac" , trie )
112
+ checkEntry (t , "a" , "a" , trie )
113
+ }
0 commit comments