1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00
Files
glusterd2/pkg/utils/statedump_test.go
Prashanth Pai 31f09bfd7d Fix TestWriteStatedump test
The unit test (TestWriteStatedump) uses a filename derived from current
timestamp and the actual code (WriteStatedump) being tested also uses
filename of the same pattern but that one may have another timestamp as
that code executes slightly later. Hence, it can so happen that the file
name written by WriteStatedump() is different than the filename expected
by the test. As these two timestamps are at seconds level granularity,
we didn't see it fail earlier.

This change modifies the test to look for a pattern that resembles
statedump file.

Signed-off-by: Prashanth Pai <ppai@redhat.com>
2018-09-14 17:11:38 +05:30

28 lines
473 B
Go

package utils
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func TestWriteStatedump(t *testing.T) {
r := require.New(t)
dir, err := ioutil.TempDir("", t.Name())
r.Nil(err)
defer os.RemoveAll(dir)
WriteStatedump(dir)
filePattern := fmt.Sprintf("glusterd2.%s.dump.*", strconv.Itoa(os.Getpid()))
matches, err := filepath.Glob(filepath.Join(dir, filePattern))
r.Nil(err)
r.NotEmpty(matches)
}