started to implements the integration tests
This commit is contained in:
1 parent
0186c30750
commit
b52129817e
5 files changed
+110
-37
No files matched your search
@@ -3,6 +3,7 @@ package payload
|
||||
import (
|
||||
"archive/zip"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
@@ -21,6 +22,16 @@ type Payload struct {
|
||||
Hash []byte
|
||||
}
|
||||
|
||||
func GetDefaultPayload(dataSource io.Reader) *Payload {
|
||||
return &Payload{
|
||||
DataSource: dataSource,
|
||||
Random: rand.Reader,
|
||||
HashMethod: SHA512,
|
||||
Block: AES256,
|
||||
BlockMode: OFB,
|
||||
}
|
||||
}
|
||||
|
||||
type payloadWriter struct {
|
||||
Reader io.Reader
|
||||
Pipewriter io.WriteCloser
|
||||
|
||||
@@ -141,5 +141,27 @@ func TestGetPayloadData(t *testing.T) {
|
||||
fmt.Println(p.GetHash())
|
||||
errorC <- errors.New("hash has not been computed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDefaultPayload(t *testing.T) {
|
||||
p := GetDefaultPayload(bytes.NewBufferString("some data to encrypt"))
|
||||
r, err := p.GetPayloadData()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
errorC := make(chan error)
|
||||
go func(errorC chan error) {
|
||||
if _, err := ioutil.ReadAll(r); err != nil {
|
||||
errorC <- err
|
||||
}
|
||||
errorC <- nil
|
||||
}(errorC)
|
||||
|
||||
if err := <-errorC; err != nil {
|
||||
t.Error(err)
|
||||
} else if len(p.GetHash()) != 512/8 {
|
||||
fmt.Println(p.GetHash())
|
||||
errorC <- errors.New("hash has not been computed")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user