bugfix: updatedAt timestamp file may be empty
Signed-off-by: Michael Wan <zirenwan@gmail.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/content/testsuite"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/assert"
|
||||
@@ -392,3 +393,24 @@ func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, r
|
||||
|
||||
assert.NilError(t, writer.Close())
|
||||
}
|
||||
|
||||
func TestWriteReadEmptyFileTimestamp(t *testing.T) {
|
||||
root, err := ioutil.TempDir("", "test-write-read-file-timestamp")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create a tmp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
emptyFile := filepath.Join(root, "updatedat")
|
||||
if err := writeTimestampFile(emptyFile, time.Time{}); err != nil {
|
||||
t.Errorf("failed to write Zero Time to file: %v", err)
|
||||
}
|
||||
|
||||
timestamp, err := readFileTimestamp(emptyFile)
|
||||
if err != nil {
|
||||
t.Errorf("read empty timestamp file should success, but got error: %v", err)
|
||||
}
|
||||
if !timestamp.IsZero() {
|
||||
t.Errorf("read empty timestamp file should return time.Time{}, but got: %v", timestamp)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user