file_test.go 1.03 KB
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1 2 3
package common

import (
Caro Axel's avatar
Caro Axel committed
4 5
	"crypto/sha512"
	"encoding/json"
Loïck Bonniot's avatar
Loïck Bonniot committed
6 7 8
	"io/ioutil"
	"testing"

9
	"github.com/stretchr/testify/assert"
Caro Axel's avatar
Caro Axel committed
10
	"gopkg.in/mgo.v2/bson"
Loïck Bonniot's avatar
Loïck Bonniot committed
11 12 13 14 15 16 17 18 19 20 21
)

func TestUnmarshalDFSSFile(t *testing.T) {
	data, err := ioutil.ReadFile("../testdata/file.dfss")
	assert.Equal(t, nil, err)

	c, err := UnmarshalDFSSFile(data)
	assert.Equal(t, nil, err)
	assert.Equal(t, "filename.pdf", c.File.Name)
	// a tiny test, full unmarshal is tested in dfss/dfssp/contract package
}
Caro Axel's avatar
Caro Axel committed
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

func TestUnmarshalRecoverDataFile(t *testing.T) {
	bsonUUID := bson.NewObjectId()
	uuid := bsonUUID.Hex()
	ttpAddrport := "127.0.0.1:0000"

	h := sha512.Sum512([]byte{7})
	ttpHash := h[:]

	recData := RecoverDataJSON{
		SignatureUUID: uuid,
		TTPAddrport:   ttpAddrport,
		TTPHash:       ttpHash,
	}

	file, err := json.MarshalIndent(recData, "", "  ")
	assert.Nil(t, err)

	unmarshal, err := UnmarshalRecoverDataFile(file)
	assert.Nil(t, err)

	assert.Equal(t, uuid, unmarshal.SignatureUUID)
	assert.Equal(t, ttpAddrport, unmarshal.TTPAddrport)
	assert.Equal(t, ttpHash, unmarshal.TTPHash)
}