0

I am not able to match response body with expected value Here is the code i have tried to POST method to create resource

func TestCreateFileShare(t *testing.T) {
    var jsonStr = []byte(`{
        "id": "bd5b12a8-a101-11e7-941e-d77981b584d8",
        "name":"fakeFileShare",
        "description":"fake Fileshare",
        "size": 1,
        "profileId": "1106b972-66ef-11e7-b172-db03f3689c9c",
        "availabilityZone": "default",
        "status": "creating",
        "createdAt":"",
        "updatedAt":""
    }`)

    t.Run("Should return 200 if everything works well", func(t *testing.T) {
        fileshare := model.FileShareSpec{BaseModel: &model.BaseModel{}}
        json.NewDecoder(bytes.NewBuffer(jsonStr)).Decode(&fileshare)
        mockClient := new(dbtest.Client)
        mockClient.On("CreateFileShare", c.NewAdminContext(), &fileshare).Return(nil, nil)
        mockClient.On("GetProfile", c.NewAdminContext(),"1106b972-66ef-11e7-b172-db03f3689c9c").Return(&SampleFileShareProfiles[0], nil)
        db.C = mockClient
        r, _ := http.NewRequest("POST", "/v1beta/file/shares", bytes.NewBuffer(jsonStr))
        fmt.Println(bytes.NewBuffer(jsonStr))

        w := httptest.NewRecorder()
        r.Header.Set("Content-Type", "application/JSON")
        beego.InsertFilter("*", beego.BeforeExec, func(httpCtx *context.Context) {
            httpCtx.Input.SetData("context", c.NewAdminContext())
        })
        beego.BeeApp.Handlers.ServeHTTP(w, r)
        assertTestResult(t, w.Code, 200)
        
    })
}

or at least i should be able to ignore some fields which are not imprortant for validation ex: createdAt, updatedAt fields

```
mock: Unexpected Method Call
-----------------------------
The closest call I have is: 
-  CreatedAt: (string) "",
-  UpdatedAt: (string) ""
+  CreatedAt: (string) (len=19) "2020-08-28T13:26:09",
+  UpdatedAt: (string) (len=19) "2020-08-28T13:26:09"
  }),
```
tech01
  • 1
  • 1

0 Answers0