Skip to content

Commit

Permalink
Add WrappedFile (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Sep 16, 2024
1 parent c216d33 commit fe8155c
Show file tree
Hide file tree
Showing 8 changed files with 3,339 additions and 41 deletions.
80 changes: 74 additions & 6 deletions file_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ func TestFileInfo_Name(t *testing.T) {
expected: "callback",
},
{
scenario: "not empty",
scenario: "no name",
mockFileInfo: aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Name").Return("name")
fi.On("Name").Return("")
}),
expected: "name",
},
{
scenario: "empty",
scenario: "has name",
mockFileInfo: aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Name").Return("")
fi.On("Name").Return("name")
}),
expected: "",
expected: "name",
},
}

Expand All @@ -55,6 +54,16 @@ func TestFileInfo_Name(t *testing.T) {
}
}

func TestFileInfo_Name_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Name")
})(t).Name()
})
}

func TestFileInfo_Size(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -93,6 +102,16 @@ func TestFileInfo_Size(t *testing.T) {
}
}

func TestFileInfo_Size_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Size")
})(t).Size()
})
}

func TestFileInfo_Mode(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -131,6 +150,16 @@ func TestFileInfo_Mode(t *testing.T) {
}
}

func TestFileInfo_Mode_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Mode")
})(t).Mode()
})
}

func TestFileInfo_ModTime(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -177,6 +206,16 @@ func TestFileInfo_ModTime(t *testing.T) {
}
}

func TestFileInfo_ModTime_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("ModTime")
})(t).ModTime()
})
}

func TestFileInfo_IsDir(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -221,6 +260,16 @@ func TestFileInfo_IsDir(t *testing.T) {
}
}

func TestFileInfo_IsDir_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("IsDir")
})(t).IsDir()
})
}

func TestFileInfo_Sys(t *testing.T) {
t.Parallel()

Expand All @@ -229,6 +278,15 @@ func TestFileInfo_Sys(t *testing.T) {
mockFileInfo aferomock.FileInfoMocker
expected interface{}
}{
{
scenario: "callback",
mockFileInfo: aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Sys").Return(func() interface{} {
return &struct{}{}
})
}),
expected: &struct{}{},
},
{
scenario: "header",
mockFileInfo: aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
Expand All @@ -249,3 +307,13 @@ func TestFileInfo_Sys(t *testing.T) {
})
}
}

func TestFileInfo_Sys_NoReturnValuePanic(t *testing.T) {
t.Parallel()

assert.Panics(t, func() {
aferomock.MockFileInfo(func(fi *aferomock.FileInfo) {
fi.On("Sys")
})(t).Sys()
})
}
Loading

0 comments on commit fe8155c

Please sign in to comment.