arnaucube
arnaucube/go-dvotePublic Self-hosted repository
go-dvote/data/data_test.go
data/data_test.goRaw
 1package data
 2
 3import (
 4	"testing"
 5	"fmt"
 6	"encoding/json"
 7	"strings"
 8)
 9
10func TestPublishAndRetrieve(t *testing.T) {
11	t.Log("Testing adding json")
12
13	exampleVote := votePacket{
14		000001,
15		"12309801002",
16		"nynnynnnynnnyy",
17		"132498-0-02103908",
18	}
19
20	testObject, err := json.Marshal(exampleVote)
21	if err != nil {
22		t.Errorf("Bad test JSON: %s", err)
23	}
24	prepub := string(testObject)
25
26	hash := publish(testObject)
27	content := retrieve(hash)
28	postpub := string(content)
29	//fmt.Println(hash)
30	//fmt.Println(string(content))
31	if strings.Compare(prepub,postpub) != 0 {
32		t.Errorf("Published file doesn't match. Expected:\n %s \n Got: \n %s \n", prepub, postpub)
33	}
34}