MCPcopy
hub / github.com/perkeep/perkeep / TestEnumerateIsSorted

Function TestEnumerateIsSorted

pkg/blobserver/files/enumerate_test.go:130–202  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestEnumerateIsSorted(t *testing.T) {
131 ds, root := NewTestStorage(t)
132 defer os.RemoveAll(root)
133
134 const blobsToMake = 250
135 t.Logf("Uploading test blobs...")
136 for i := 0; i < blobsToMake; i++ {
137 blob := &test.Blob{Contents: fmt.Sprintf("blob-%d", i)}
138 blob.MustUpload(t, ds)
139 }
140
141 // Make some fake blobs in other partitions to confuse the
142 // enumerate code.
143 // TODO(bradfitz): remove this eventually.
144 fakeDir := root + "/partition/queue-indexer/sha1/1f0/710"
145 if err := os.MkdirAll(fakeDir, 0755); err != nil {
146 t.Fatalf("error creating fakedir: %v", err)
147 }
148 if err := os.WriteFile(
149 fakeDir+"/sha1-1f07105465650aa243cfc1b1bbb1c68ea95c6812.dat",
150 []byte("fake file"),
151 0644,
152 ); err != nil {
153 t.Fatalf("error writing fake blob: %v", err)
154 }
155
156 // And the same for a "cache" directory, used by the default configuration.
157 fakeDir = root + "/cache/sha1/1f0/710"
158 if err := os.MkdirAll(fakeDir, 0755); err != nil {
159 t.Fatalf("error creating cachedir: %v", err)
160 }
161 if err := os.WriteFile(
162 fakeDir+"/sha1-1f07105465650aa243cfc1b1bbb1c68ea95c6812.dat",
163 []byte("fake file"),
164 0644,
165 ); err != nil {
166 t.Fatalf("error writing fake file: %v", err)
167 }
168
169 var tests = []struct {
170 limit int
171 after string
172 }{
173 {200, ""},
174 {blobsToMake, ""},
175 {200, "sha1-2"},
176 {200, "sha1-3"},
177 {200, "sha1-4"},
178 {200, "sha1-5"},
179 {200, "sha1-e"},
180 {200, "sha1-f"},
181 {200, "sha1-ff"},
182 }
183 for _, test := range tests {
184 limit := test.limit
185 ch := make(chan blob.SizedRef)
186 errCh := make(chan error)
187 go func() {

Callers

nothing calls this directly

Calls 7

MustUploadMethod · 0.95
NewTestStorageFunction · 0.85
SortedSizedBlobsTypeAlias · 0.85
LogfMethod · 0.80
MkdirAllMethod · 0.65
FatalfMethod · 0.65
EnumerateBlobsMethod · 0.65

Tested by

no test coverage detected