Skip to content

Instantly share code, notes, and snippets.

@jcdan3
Last active December 12, 2021 20:02
Show Gist options
  • Select an option

  • Save jcdan3/d42bbd747d6590355789a486bacb094b to your computer and use it in GitHub Desktop.

Select an option

Save jcdan3/d42bbd747d6590355789a486bacb094b to your computer and use it in GitHub Desktop.
package mockingdemo
import (
"golangtips/mockingdemo/mocks"
"testing"
)
func TestFileSystem_PrintFileContent(t *testing.T) {
type fields struct {
conn FileConnector
}
const fileToRead = "mockFileToread.txt"
connectorMock := mocks.FileConnector{}
connectorMock.On("ReadFromFile", fileToRead).Return([]byte("hello"),nil)
type args struct {
fileName string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
"test",
fields{&connectorMock},
args{fileName: fileToRead},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fs := &FileSystem{
conn: tt.fields.conn,
}
if err := fs.PrintFileContent(tt.args.fileName); (err != nil) != tt.wantErr {
t.Errorf("PrintFileContent() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment