Last active
December 12, 2021 20:02
-
-
Save jcdan3/d42bbd747d6590355789a486bacb094b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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