From 3f2614edeb439676c9770a75f964b90fbb494216 Mon Sep 17 00:00:00 2001 From: sankari gopalakrishnan Date: Tue, 19 Dec 2023 13:08:38 +0100 Subject: [PATCH 1/2] Adding unit tests to workflowHandler_test.go --- service/frontend/workflowHandler_test.go | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/service/frontend/workflowHandler_test.go b/service/frontend/workflowHandler_test.go index 50b0ec47a86..d2665fa5eb4 100644 --- a/service/frontend/workflowHandler_test.go +++ b/service/frontend/workflowHandler_test.go @@ -702,6 +702,51 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Success_NotEnabled() { s.NoError(err) } +func (s *workflowHandlerSuite) TestListDomains_Success() { + listDomainResp := &persistence.ListDomainsResponse{ + Domains: []*persistence.GetDomainResponse{ + persistenceGetDomainResponse( + &domain.ArchivalState{Status: types.ArchivalStatusDisabled, URI: ""}, + &domain.ArchivalState{Status: types.ArchivalStatusDisabled, URI: ""}, + ), + persistenceGetDomainResponse( + &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: ""}, + &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: ""}, + ), + }, + } + s.mockMetadataMgr.On("ListDomains", mock.Anything, mock.Anything).Return(listDomainResp, nil) + + wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) + result, err := wh.ListDomains(context.Background(), &types.ListDomainsRequest{}) + + s.NoError(err) + s.NotNil(result) + s.Equal(2, len(result.GetDomains())) +} + +func (s *workflowHandlerSuite) TestListDomains_RequestNotSet() { + wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) + result, err := wh.ListDomains(context.Background(), nil) + + s.Error(err) + s.Nil(result) +} + +func (s *workflowHandlerSuite) TestHealth_StatusOK() { + wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) + + result, err := wh.Health(context.Background()) + s.NoError(err) + s.False(result.Ok) + + wh.UpdateHealthStatus(HealthStatusOK) + result, err = wh.Health(context.Background()) + + s.NoError(err) + s.True(result.Ok) +} + func (s *workflowHandlerSuite) TestDescribeDomain_Success_ArchivalDisabled() { getDomainResp := persistenceGetDomainResponse( &domain.ArchivalState{Status: types.ArchivalStatusDisabled, URI: ""}, From 1e1ae88b351b15bf5d992463298abda5eab0a7dc Mon Sep 17 00:00:00 2001 From: sankari gopalakrishnan Date: Wed, 20 Dec 2023 13:31:30 +0100 Subject: [PATCH 2/2] Update workflowHandler_test.go --- service/frontend/workflowHandler_test.go | 31 ++++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/service/frontend/workflowHandler_test.go b/service/frontend/workflowHandler_test.go index d2665fa5eb4..96c8614329c 100644 --- a/service/frontend/workflowHandler_test.go +++ b/service/frontend/workflowHandler_test.go @@ -703,46 +703,45 @@ func (s *workflowHandlerSuite) TestRegisterDomain_Success_NotEnabled() { } func (s *workflowHandlerSuite) TestListDomains_Success() { + domain := persistenceGetDomainResponse( + &domain.ArchivalState{}, + &domain.ArchivalState{}, + ) listDomainResp := &persistence.ListDomainsResponse{ Domains: []*persistence.GetDomainResponse{ - persistenceGetDomainResponse( - &domain.ArchivalState{Status: types.ArchivalStatusDisabled, URI: ""}, - &domain.ArchivalState{Status: types.ArchivalStatusDisabled, URI: ""}, - ), - persistenceGetDomainResponse( - &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: ""}, - &domain.ArchivalState{Status: types.ArchivalStatusEnabled, URI: ""}, - ), + domain, + domain, }, } - s.mockMetadataMgr.On("ListDomains", mock.Anything, mock.Anything).Return(listDomainResp, nil) - + s.mockMetadataMgr. + On("ListDomains", mock.Anything, mock.Anything). + Return(listDomainResp, nil) wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) - result, err := wh.ListDomains(context.Background(), &types.ListDomainsRequest{}) + result, err := wh.ListDomains(context.Background(), &types.ListDomainsRequest{}) s.NoError(err) - s.NotNil(result) s.Equal(2, len(result.GetDomains())) } func (s *workflowHandlerSuite) TestListDomains_RequestNotSet() { wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) - result, err := wh.ListDomains(context.Background(), nil) + result, err := wh.ListDomains(context.Background(), nil /* list request is not set */) s.Error(err) + s.Equal(errRequestNotSet, err) s.Nil(result) } func (s *workflowHandlerSuite) TestHealth_StatusOK() { - wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) + wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) // workflow handler gets initial health status as HealthStatusWarmingUp - result, err := wh.Health(context.Background()) + result, err := wh.Health(context.Background()) // Health check looks for HealthStatusOK s.NoError(err) s.False(result.Ok) wh.UpdateHealthStatus(HealthStatusOK) - result, err = wh.Health(context.Background()) + result, err = wh.Health(context.Background()) s.NoError(err) s.True(result.Ok) }