-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimulation_state_test.go
60 lines (50 loc) · 1.54 KB
/
simulation_state_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
package master
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
const testStatesFolderName = "states-test"
func cleanup() {
err := os.RemoveAll(testStatesFolderName)
if err != nil {
panic(err)
}
}
func TestNameOfLatestState(t *testing.T) {
defer cleanup()
err := os.MkdirAll(filepath.Join(testStatesFolderName), 0755)
_, err = os.Create(filepath.Join(testStatesFolderName, "STATE_20190222194317"))
_, err = os.Create(filepath.Join(testStatesFolderName, "STATE_20190222194284"))
_, err = os.Create(filepath.Join(testStatesFolderName, "STAT_201902A22194284"))
files, err := ioutil.ReadDir(filepath.Join(testStatesFolderName))
if err != nil {
log.Fatal("creating or reading files for test failed")
}
assert.Equal(t, "STATE_20190222194317", nameOfLatestState(files))
}
func TestStateNameValid(t *testing.T) {
t.Run("with valid state name", func(t *testing.T) {
stateName := "STATE_20190222194317"
assert.True(t, stateNameValid(stateName))
})
t.Run("with invalid state name", func(t *testing.T) {
stateName := "STTE_2019022a2194241"
assert.False(t, stateNameValid(stateName))
})
}
func TestStateNameToInt(t *testing.T) {
t.Run("with valid state name", func(t *testing.T) {
stateName := "STATE_20190222194241"
stateInt, _ := stateNameToInt(stateName)
assert.Equal(t, int64(20190222194241), stateInt)
})
t.Run("with invalid state name", func(t *testing.T) {
stateName := "STTE_2019022a2194241"
stateInt, _ := stateNameToInt(stateName)
assert.Equal(t, int64(0), stateInt)
})
}