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