-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: use namespace.Name and namespace.ID in tests #7065
Refactor: use namespace.Name and namespace.ID in tests #7065
Conversation
namespace namespace.Name | ||
namespaceID namespace.ID | ||
foreignNamespace namespace.Name | ||
archivalNamespace namespace.Name | ||
archivalNamespaceID namespace.ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespaceName.
foreignNamespaceName.
etc.
otherwise - why namespaceID for namespace.ID but just namespace for namespace.Name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name
orID
can be inferred from type of the field (one of the reason of this PR)- We all get used to just "namespace" mostly means name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets be clear and consistent, and think about future readers.
We have Namespace struct
, so no, it is not clear that 'namespace` is name.
so if this represents namespace.Name - please rename this to namespaceName.
4948d49
to
42f3e98
Compare
tests/archival_test.go
Outdated
@@ -321,7 +316,8 @@ func (s *ArchivalSuite) isMutableStateDeleted(namespaceID string, execution *com | |||
} | |||
|
|||
func (s *ArchivalSuite) startAndFinishWorkflow( | |||
id, wt, tq, namespace, namespaceID string, | |||
id, wt, tq string, | |||
namespace namespace.Name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. You are sending in namespace.Name structure, but using only namespace name as a string.
Just send string (as it was before).
You can rename it to namespaceName or nsName
namespace namespace.Name | ||
namespaceID namespace.ID | ||
foreignNamespace namespace.Name | ||
archivalNamespace namespace.Name | ||
archivalNamespaceID namespace.ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespaceName.
foreignNamespaceName.
etc.
otherwise - why namespaceID for namespace.ID but just namespace for namespace.Name?
@@ -127,15 +130,23 @@ func (s *FunctionalTestBase) HttpAPIAddress() string { | |||
return s.httpAPIAddress | |||
} | |||
|
|||
func (s *FunctionalTestBase) Namespace() string { | |||
func (s *FunctionalTestBase) Namespace() namespace.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NamespaceName()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also return string. There is no point of returning napespace.name structure, given that it is a thin wrapper over stirng.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a point. And this is a goal of this PR. Both Namespace.ID
and Namespace.Name
are string
, and it is easy to mess the up. Having distinct types in the code helps this. Major part of server code is using those distinct types already. This is just a follow-up for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what is easy to mess up in
func (s *FunctionalTestBase) NamespaceName() string {
?
or in NamespaceID() string.
we are mostly working with strings, but you can't use namespace.Name directly, you still need to call String().
So no, namespace.Name is not a string.
s.Namespace().String() is unnecessary verbose, and not adding anything.
s.NamespaceName() is much cleaner.
return s.namespaceID | ||
} | ||
|
||
func (s *FunctionalTestBase) ArchivalNamespace() namespace.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArchivalNamespaceName()
return s.archivalNamespaceID | ||
} | ||
|
||
func (s *FunctionalTestBase) ForeignNamespace() namespace.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForeignNamespaceName
s.namespace = RandomizeStr("namespace") | ||
s.Require().NoError(s.registerNamespaceWithDefaults(s.namespace)) | ||
s.namespace = namespace.Name(RandomizeStr("namespace")) | ||
s.namespaceID, err = s.registerNamespaceWithDefaults(s.Namespace()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only place where you actually assign namespace.ID to something.
You may just add the code that gets namespace ID from namespace here, and avoid returning something that is mostly not used.
@@ -355,17 +369,28 @@ func (s *FunctionalTestBase) registerNamespace( | |||
}, | |||
}, | |||
}) | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are not using this value in anywhere directly
remove this return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are asserts that err
is nil
on caller side.
|
||
return err | ||
descResp, err := s.client.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this code to that only place where you actually need namespace ID
@@ -134,7 +133,7 @@ func (s *ActivityApiPauseClientTestSuite) TestActivityPauseApi_WhileRunning() { | |||
|
|||
// pause activity | |||
pauseRequest := &workflowservice.PauseActivityByIdRequest{ | |||
Namespace: s.Namespace(), | |||
Namespace: s.Namespace().String(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is more inconvenient then before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More typing, yes. More inconvenient, no.
} | ||
|
||
func (s *FunctionalTestBase) markNamespaceAsDeleted( | ||
namespace string, | ||
nsName namespace.Name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and everywhere below.
What is the benefit of changing string to namespace.Name?
You are only using it as nsName.String()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied in another comment.
descResp, err := s.client.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ | ||
Namespace: nsName.String(), | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not there anymore.
What changed?
Refactor: use
namespace.Name
andnamespace.ID
instead ofstring
in tests.Why?
Special narrow types should be used where possible.
How did you test it?
Run tests.
Potential risks
No risks.
Documentation
No.
Is hotfix candidate?
No.