Skip to content

Commit

Permalink
Test cases for issue kubernetes#3044 - timestamps of mounted files in…
Browse files Browse the repository at this point in the history
…correct with windows host.
  • Loading branch information
ngoozeff committed Oct 31, 2018
1 parent 8256665 commit 14244b3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/integration/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ func TestMain(m *testing.M) {
var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary")
var args = flag.String("minikube-args", "", "Arguments to pass to minikube")
var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start")
var mountArgs = flag.String("minikube-mount-args", "", "Arguments to pass to minikube mount")
var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives")

func NewMinikubeRunner(t *testing.T) util.MinikubeRunner {
return util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
StartArgs: *startArgs,
MountArgs: *mountArgs,
T: t,
}
}
20 changes: 19 additions & 1 deletion test/integration/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func testMounting(t *testing.T) {
}
defer os.RemoveAll(tempDir)

mountCmd := fmt.Sprintf("mount %s:/mount-9p", tempDir)
mountCmd := fmt.Sprintf("mount %s %s:/mount-9p", minikubeRunner.MountArgs, tempDir)
cmd, _ := minikubeRunner.RunDaemon(mountCmd)
defer func() {
err := cmd.Process.Kill()
Expand Down Expand Up @@ -118,6 +118,24 @@ func testMounting(t *testing.T) {
t.Fatalf("Expected file %s to contain text %s, was %s.", path, expected, out)
}

// test file timestamps are correct
files := []string{"fromhost", "frompod"}
for _, file := range files {
statCmd := fmt.Sprintf("stat /mount-9p/%s", file)
statOutput, err := minikubeRunner.SSH(statCmd)
if err != nil {
t.Fatalf("%v", err)
}

if strings.Contains(statOutput, "Access: 1970-01-01") {
t.Fatalf("Invalid access time\n%s", statOutput)
}

if strings.Contains(statOutput, "Modify: 1970-01-01") {
t.Fatalf("Invalid modify time\n%s", statOutput)
}
}

// test that fromhostremove was deleted by the pod from the mount via rm /mount-9p/fromhostremove
path = filepath.Join(tempDir, "fromhostremove")
if _, err := os.Stat(path); err == nil {
Expand Down
1 change: 1 addition & 0 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type MinikubeRunner struct {
BinaryPath string
Args string
StartArgs string
MountArgs string
}

func (m *MinikubeRunner) Run(cmd string) error {
Expand Down
53 changes: 53 additions & 0 deletions third_party/go9p/ufs_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package go9p

import (
"fmt"
"os"
"testing"
)

func assert_NotNil(t *testing.T, i interface {}) {
if (i == nil) {
t.Error("Value should not be nil")
}
}

func assert_NotEqual(t *testing.T, lhs uint32, rhs uint32, message string) {
if (lhs == rhs) {
t.Errorf("Value %d should not be %d. %s", lhs, rhs, message)
}
}

func TestDir2DirTimestamp(t *testing.T) {
fi, err := os.Stat(".")
if err != nil {
t.Error(err)
}
var st *Dir
st, _ = dir2Dir(".", fi, false, nil)
assert_NotNil(t, st)

if testing.Verbose() {
fmt.Printf("%s %d %d\n", st.Name, st.Mtime, st.Atime)
}

assert_NotEqual(t, st.Mtime, uint32(0), "Mtime should be set")
assert_NotEqual(t, st.Atime, uint32(0), "Atime should be set")
}

func TestDir2DirTimestampDotu(t *testing.T) {
fi, err := os.Stat(".")
if err != nil {
t.Error(err)
}
var st *Dir
st, _ = dir2Dir(".", fi, true, nil)
assert_NotNil(t, st)

if testing.Verbose() {
fmt.Printf("%s %d %d\n", st.Name, st.Mtime, st.Atime)
}

assert_NotEqual(t, st.Mtime, uint32(0), "Mtime should be set")
assert_NotEqual(t, st.Atime, uint32(0), "Atime should be set")
}

0 comments on commit 14244b3

Please sign in to comment.