This repository has been archived by the owner on Feb 21, 2020. It is now read-only.
forked from monmohan/xferspdy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd_test.go
67 lines (57 loc) · 1.54 KB
/
cmd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2015 Monmohan Singh. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xferspdy
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"testing"
)
var (
filev1 = "testdata/SamplePPT_v1.pptx"
fprint = "testdata/SamplePPT_v1.pptx.fingerprint"
filev2 = "testdata/SamplePPT_v2.pptx"
fpatch = "testdata/SamplePPT_v2.pptx.patch"
patchedFile = "testdata/Patched_SamplePPT_v1.pptx"
)
func TestCmdUtilities(t *testing.T) {
cleanup()
defer cleanup()
//fpgen
var cmd = exec.Command(fmt.Sprintf("%s/bin/fpgen", os.ExpandEnv("$GOPATH")), "-file", filev1)
handleCommand(cmd, t)
//diff
cmd = exec.Command(fmt.Sprintf("%s/bin/diff", os.ExpandEnv("$GOPATH")), "-file", filev2, "-fingerprint", fprint)
handleCommand(cmd, t)
//patch
cmd = exec.Command(fmt.Sprintf("%s/bin/patch", os.ExpandEnv("$GOPATH")), "-base", filev1, "-patch", fpatch)
handleCommand(cmd, t)
sign1 := NewFingerprint(filev2, uint32(2048))
sign2 := NewFingerprint(patchedFile, uint32(2048))
if sign1.DeepEqual(sign2) {
fmt.Printf("Signature matched %s %s \n", sign1.Source, sign2.Source)
} else {
t.Fail()
}
}
func handleCommand(cmd *exec.Cmd, t *testing.T) {
var out bytes.Buffer
var eout bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &eout
err := cmd.Run()
if err != nil {
fmt.Printf("Error %q\n", eout.String())
log.Fatal(err)
t.FailNow()
}
fmt.Printf("Output %q\n", out.String())
}
func cleanup() {
os.Remove(fprint)
os.Remove(fpatch)
os.Remove(patchedFile)
}