Welcome to the world of Go.

The formatting of your snipped does not seem quite right to me, 
which makes it hard for me to read.

I would try to put a minimal runnable example which reproduces the problem 
in https://play.golang.org/
and posting it here.

Best,
Amnon

On Friday, 28 August 2020 18:08:58 UTC+1, Shruthi mn wrote:
>
>
> Here is my code snippet
> ```
> 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":"" }`) var expectedJson = 
> []byte(`{ "id": "bd5b12a8-a101-11e7-941e-d77981b584d8", "name": 
> "fakeFileShare", "description": "fake FileShare", "size": 1, "status": 
> "available", "poolId": "084bf71e-a102-11e7-88a8-e31fe6d52248", "profileId": 
> "1106b972-66ef-11e7-b172-db03f3689c9c" }`) var expected model.FileShareSpec 
> json.Unmarshal(expectedJson, &expected) 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(&expected, nil).Once() mockClient.On("GetProfile", 
> c.NewAdminContext(),"1106b972-66ef-11e7-b172-db03f3689c9c").Return(&SampleFileShareProfiles[0],
>  
> nil) //mockClient.TestData(&SampleFileShareProfiles) 
> //mockClient.On().Return() 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) var output model.FileShareSpec 
> json.Unmarshal(w.Body.Bytes(), &output)) assertTestResult(t, w.Code, 200) 
> assertTestResult(t, &output, &expected) }) } 
> ```
> I am geeting error 
> ```
> mock: Unexpected Method Call
> -----------------------------
>
> CreateFileShare(*context.Context,*model.FileShareSpec)
>         0: &context.Context{AuthToken:"", UserId:"", TenantId:"", 
> DomainId:"", UserDomainId:"", ProjectDomainId:"", IsAdmin:true, 
> ReadOnly:"", ShowDeleted:"", RequestId:"", ResourceUuid:"", Overwrite:"", 
> Roles:[]string(nil), UserName:"", ProjectName:"", DomainName:"", 
> UserDomainName:"", ProjectDomainName:"", IsAdminProject:false, 
> ServiceToken:"", ServiceUserId:"", ServiceUserName:"", 
> ServiceUserDomainId:"", ServiceUserDomainName:"", ServiceProjectId:"", 
> ServiceProjectName:"", ServiceProjectDomainId:"", 
> ServiceProjectDomainName:"", ServiceRoles:"", Token:"", Uri:""}
>         1: 
> &model.FileShareSpec{BaseModel:(*model.BaseModel)(0xc000494510), 
> TenantId:"", UserId:"", Name:"fakeFileShare", Protocols:[]string(nil), 
> Description:"fake Fileshare", Size:1, AvailabilityZone:"default", 
> Status:"creating", PoolId:"", 
> ProfileId:"1106b972-66ef-11e7-b172-db03f3689c9c", SnapshotId:"", 
> SnapshotName:"", ExportLocations:[]string(nil), 
> Metadata:map[string]string(nil)}
>
> The closest call I have is: 
>
> CreateFileShare(*context.Context,*model.FileShareSpec)
>         0: &context.Context{AuthToken:"", UserId:"", TenantId:"", 
> DomainId:"", UserDomainId:"", ProjectDomainId:"", IsAdmin:true, 
> ReadOnly:"", ShowDeleted:"", RequestId:"", ResourceUuid:"", Overwrite:"", 
> Roles:[]string(nil), UserName:"", ProjectName:"", DomainName:"", 
> UserDomainName:"", ProjectDomainName:"", IsAdminProject:false, 
> ServiceToken:"", ServiceUserId:"", ServiceUserName:"", 
> ServiceUserDomainId:"", ServiceUserDomainName:"", ServiceProjectId:"", 
> ServiceProjectName:"", ServiceProjectDomainId:"", 
> ServiceProjectDomainName:"", ServiceRoles:"", Token:"", Uri:""}
>         1: 
> &model.FileShareSpec{BaseModel:(*model.BaseModel)(0xc000494090), 
> TenantId:"", UserId:"", Name:"fakeFileShare", Protocols:[]string(nil), 
> Description:"fake Fileshare", Size:1, AvailabilityZone:"default", 
> Status:"creating", PoolId:"", 
> ProfileId:"1106b972-66ef-11e7-b172-db03f3689c9c", SnapshotId:"", 
> SnapshotName:"", ExportLocations:[]string(nil), 
> Metadata:map[string]string(nil)}
>
> Difference found in argument 1:
>
> --- Expected
> +++ Actual
> @@ -3,4 +3,4 @@
>    Id: (string) (len=36) "bd5b12a8-a101-11e7-941e-d77981b584d8",
> -  CreatedAt: (string) "",
> -  UpdatedAt: (string) ""
> +  CreatedAt: (string) (len=19) "2020-08-28T13:26:09",
> +  UpdatedAt: (string) (len=19) "2020-08-28T13:26:09"
>   }),
> ```
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f8fe5b42-2675-47c9-ac09-3f94ea0f76f0o%40googlegroups.com.

Reply via email to