mirror of https://github.com/perkeep/perkeep.git
integration/camput: check we upload same file only once
Fixes issue #547 Change-Id: If9d4dcb9003f2374efb0c0f4adcfa3ee94088e10
This commit is contained in:
parent
8d37fd1a6f
commit
7fa4f9a2ee
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -103,3 +104,31 @@ func TestCamputSocket(t *testing.T) {
|
|||
out = test.MustRunCmd(t, w.Cmd("camget", br))
|
||||
t.Logf("Retrieved stored socket schema: %s", out)
|
||||
}
|
||||
|
||||
// Test that camput twice on the same file only uploads once.
|
||||
func TestCamputUploadOnce(t *testing.T) {
|
||||
w := test.GetWorld(t)
|
||||
|
||||
wantBlobRef := "sha1-0b3cff9c02e3ba02f745d861cf6550335ef55c2f"
|
||||
out := test.MustRunCmd(t, w.Cmd("camput", "file", filepath.FromSlash("../testdata/server-config.json")))
|
||||
out = strings.TrimSpace(out)
|
||||
if out != wantBlobRef {
|
||||
t.Fatalf("wrong camput output; wanted %v, got %v", wantBlobRef, out)
|
||||
}
|
||||
|
||||
cmd := w.Cmd("camput", "file", filepath.FromSlash("../testdata/server-config.json"))
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("second camput failed: %v, stdout: %v, stderr: %v", err, output, stderr.String())
|
||||
}
|
||||
out = strings.TrimSpace(string(output))
|
||||
if out != wantBlobRef {
|
||||
t.Fatalf("wrong 2nd camput output; wanted %v, got %v", wantBlobRef, out)
|
||||
}
|
||||
wantStats := `[uploadRequests=[blobs=0 bytes=0] uploads=[blobs=0 bytes=0]]`
|
||||
if !strings.Contains(stderr.String(), wantStats) {
|
||||
t.Fatalf("Wrong stats for 2nd camput upload; wanted %v, got %v", wantStats, out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue