-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
81 lines (70 loc) · 2.2 KB
/
main_test.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2025 Avi Brender.
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the License, or any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
package main_test
import (
"bytes"
"decoder"
"os"
"path"
"path/filepath"
"testing"
"time"
)
func TestRun(t *testing.T) {
mtime := time.UnixMilli(0)
tests := []struct {
testName string
inputFile string
goldenFile string
}{
{
testName: "bgw210-700",
inputFile: "testdata/bgw210-700/mfg.dat", // Fake file created using make-fake-mfg-dat-bgw210-700.sh
goldenFile: "testdata/bgw210-700/123ABC-P67AB2DR253311.tar.gz",
},
{
testName: "bgw320-500",
inputFile: "testdata/bgw320-500/calibration_01.bin",
goldenFile: "testdata/bgw320-500/123ABC-P67AB2DR253312.tar.gz",
},
{
testName: "bgw320-505",
inputFile: "testdata/bgw320-505/calibration_01.bin",
goldenFile: "testdata/bgw320-505/123ABC-P67AB2DR253313.tar.gz",
},
{
testName: "bgw620-700",
inputFile: "testdata/bgw620-700/calibration_01.bin",
goldenFile: "testdata/bgw620-700/123ABC-P67AB2DR253314.tar.gz",
},
}
for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
tempDir := t.TempDir() // This directory is automatically removed when the test completes.
if err := main.Run(test.inputFile, tempDir, mtime); err != nil {
t.Fatalf("run() failed: %v", err)
}
want := mustReadFile(t, test.goldenFile)
filename := path.Base(test.goldenFile)
gotFile := filepath.Join(tempDir, filename)
got := mustReadFile(t, gotFile)
if !bytes.Equal(got, want) {
t.Fatalf("contents of golden file (%q) and actual file (%q) are not equal", test.goldenFile, gotFile)
}
})
}
}
func mustReadFile(t *testing.T, path string) []byte {
t.Helper()
contents, err := os.ReadFile(path)
if err != nil {
t.Fatalf("could not read file %q: %v", path, err)
}
return contents
}