Test in parallel. Remove logging

This commit is contained in:
tigp
2018-05-01 17:33:39 +02:00
parent 6694f59c89
commit dc9afd860d
2 changed files with 87 additions and 76 deletions

View File

@@ -4,7 +4,6 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -65,20 +64,23 @@ func TestReaderCanReadPDF(t *testing.T) {
for _, f := range files {
ext := filepath.Ext(f.Name())
if ext != ".pdf" {
fmt.Printf("Skipping file %s\n", f.Name())
t.Log("Skipping file", f.Name())
continue
}
t.Run("", func(st *testing.T) {
st.Parallel()
input_file, err := os.Open("../testfiles/" + f.Name())
if err != nil {
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
finfo, err := input_file.Stat()
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
size := finfo.Size()
@@ -86,11 +88,13 @@ func TestReaderCanReadPDF(t *testing.T) {
_, err = pdf.NewReader(input_file, size)
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
input_file.Close()
})
}
}
@@ -128,24 +132,29 @@ func TestSignPDF(t *testing.T) {
certificate_chains := make([][]*x509.Certificate, 0)
for _, f := range files {
f := f
ext := filepath.Ext(f.Name())
if ext != ".pdf" {
fmt.Printf("Skipping file %s\n", f.Name())
t.Log("Skipping file", f.Name())
continue
}
fmt.Printf("Signing file %s\n", f.Name())
t.Run(f.Name(), func(st *testing.T) {
st.Parallel()
//t.Log("Signing file", f.Name())
input_file, err := os.Open("../testfiles/" + f.Name())
if err != nil {
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
finfo, err := input_file.Stat()
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
st.Error("%s: %s", f.Name(), err.Error())
return
}
size := finfo.Size()
@@ -153,7 +162,7 @@ func TestSignPDF(t *testing.T) {
rdr, err := pdf.NewReader(input_file, size)
if err != nil {
input_file.Close()
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
@@ -184,15 +193,17 @@ func TestSignPDF(t *testing.T) {
if err != nil {
input_file.Close()
os.Remove(outputFile.Name())
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
return
}
_, err = verify.Verify(outputFile)
input_file.Close()
os.Remove(outputFile.Name())
if err != nil {
t.Errorf("%s: %s", f.Name(), err.Error())
st.Errorf("%s: %s", f.Name(), err.Error())
}
})
}
}

View File

@@ -10,13 +10,13 @@ import (
"os"
"time"
"crypto"
"bitbucket.org/digitorus/pdf"
"bitbucket.org/digitorus/pdfsign/revocation"
"crypto"
"github.com/digitorus/pkcs7"
"github.com/digitorus/timestamp"
"golang.org/x/crypto/ocsp"
"log"
)
type Response struct {
@@ -187,10 +187,10 @@ func Verify(file *os.File) (apiResp *Response, err error) {
signer.ValidSignature = true
signer.TrustedIssuer = false
}
log.Println("Invalid sig")
//log.Println("Invalid sig")
apiResp.Error = fmt.Sprintln("Failed to verify signature:", err)
} else {
log.Println("Valid sig")
//log.Println("Valid sig")
signer.ValidSignature = true
signer.TrustedIssuer = true
}