aboutsummaryrefslogtreecommitdiffstats
path: root/demo/mvd/parse_test.go
blob: 53a00a3164bd8deaa29cffd346c34134635338f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package mvd

import (
	"crypto/sha256"
	"fmt"
	"io/ioutil"
	"testing"

	"github.com/osm/quake/common/context"
)

type mvdTest struct {
	filePath string
	checksum string
}

var mvdTests = []mvdTest{
	{
		filePath: "testdata/demo1.mvd",
		checksum: "9489430c9513aed5b8e444df1b0d2040acb55de565c1b3e237dce51c8c103c57",
	},
	{
		filePath: "testdata/demo2.mvd",
		checksum: "d40c3864dd3c052a8379e7e589cd045814ec462f6cf4432a2c94ec740843e30d",
	},
	{
		filePath: "testdata/demo3.mvd",
		checksum: "3dd728aa90fdae100ade62d9b93220b7689f6ebdca6c986d3c2b1208b4e1e33c",
	},
	{
		filePath: "testdata/demo4.mvd",
		checksum: "1f7b2c0ad77608f431028c8e68904400fe406150875a51f793f3395bf3784c90",
	},
}

func TestParse(t *testing.T) {
	for _, mt := range mvdTests {
		t.Run(mt.filePath, func(t *testing.T) {
			data, err := ioutil.ReadFile(mt.filePath)
			if err != nil {
				t.Errorf("unable to open demo file, %v", err)
			}

			demo, err := Parse(context.New(), data)
			if err != nil {
				t.Errorf("unable to parse demo, %v", err)
			}

			h := sha256.New()
			h.Write(demo.Bytes())
			checksum := fmt.Sprintf("%x", h.Sum(nil))
			if checksum != mt.checksum {
				t.Errorf("sha256 checksums didn't match")
				t.Logf("output: %#v", checksum)
				t.Logf("expected: %#v", mt.checksum)
			}
		})
	}
}