I'm trying to execute unit test for below function but it not completely executing all line.
func (a API) FetchingTextFile() gin.HandlerFunc {
return func(c *gin.Context) {
f := c.Param("fileType")
files, _, err := a.grid.ListObjects(a.gridBucket, f+"/")
if err != nil {
log.Error().Caller().Err(err).Msgf("failed to retrieve files )
return
}
c.JSON(http.StatusOK, files)
}
}
its not executing after line *return func(c gin.Context) { why is that so any thoughts on same.
Test cases added below,
func Test_FetchingTextFile(t *testing.T) {
type fields struct {
grid: tt.fields.grid,
}
tests := []struct {
name string
fields fields
want gin.HandlerFunc
}{
{
name: "Get file test",
grid: &AgentMocking{
err: nil,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := API{
grid: tt.fields.grid,
}
// just for checking context
ctx := r.Context()
ctx = context.WithValue(ctx, "fileType", "text")
r = r.WithContext(ctx)
if got := a.FetchingTextFile(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FetchingTextFile() = %v, want %v", got, tt.want)
}
})
}
}