-
Notifications
You must be signed in to change notification settings - Fork 111
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
testing(dot): create dot unit tests #2112
Conversation
Codecov Report
@@ Coverage Diff @@
## development #2112 +/- ##
===============================================
+ Coverage 58.50% 61.73% +3.22%
===============================================
Files 214 216 +2
Lines 28182 28179 -3
===============================================
+ Hits 16489 17395 +906
+ Misses 10037 9039 -998
- Partials 1656 1745 +89
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
dot/build_spec_test.go
Outdated
if tt.want != nil { | ||
assert.Equal(t, tt.want.genesis.Name, got.genesis.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.
Can you assert the entire BuildSpec here 🤔 ?
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 check the entire BuildSpec because it would require comparing the code
entry which is very large.
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.
Maybe just force set the code field to empty for the actual value and assert the rest?
Like
actual := ...
actual.code = nil
expected := &BuildSpec{...}
assert.Equal(t, expected, actual)
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.
can we resolve this or does this need to updated?
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.
Updated to force set genesis Raw and Runtime fields before comparing.
dot/build_spec_test.go
Outdated
if tt.want != nil { | ||
assert.Equal(t, tt.want.genesis.Name, got.genesis.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.
Can you assert the entire buildSpec? Or is there some random aspect to it? Or set unexported fields?
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.
can we resolve this or does this need to updated?
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.
Updated to test buildSpec.
@edwardmack this branch is failing to compile. |
bed245e
to
2a4db58
Compare
46dd3ab
to
a2bebe1
Compare
I've cleaned up conflicts with this, it should be ready for re-review. |
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.
basically looks good just a few comments!
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.
TestNewTestGenesisAndRuntime
is failing when I run this locally.
@timwu20 |
Looks like on MacOS it writes to a different folder than |
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.
Can you move all the NewTestXXX
functions into a test file. All the references to these functions are only in test files. Then you don't need to write unit tests for them 😉
I've updated this test. |
Good point, I've moved these. |
I've created a new PR #2446, to replace this PR. The new PR has been cleaned-up to show the files that were actually updated for this PR. I believe all the comments for this have been addressed, please see review the new PR. |
15993cc
to
c145175
Compare
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.
@edwardmack there are still a few unresolved comments I read through above.
I also took the liberty to force push the squashed commits from your new branch from #2112 to this PR's branch so Github keeps track of already reviewed changes, to avoid re-reviewing 4k+ lines from scratch for me and other reviewers.
FYI Github changes web view works by comparing squashed changes vs the first commit the branch has branched out off. That means that rewriting history (like force pushing squashed commits here) is fine and won't affect reviewers changes viewed.
go func() { | ||
<-node.started | ||
node.Stop() | ||
}() | ||
err = node.Start() | ||
require.NoError(t, err) | ||
<-node.started | ||
node.Stop() |
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.
Maybe it was better before? Start
launches a goroutine to handle the node I think, so it should be fine to call all this synchronously. Plus if the start fails and returns a start error, node.started
will never get closed
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 seems that node.Start() blocks until node.Stop is called. There is a WaitGroup in start that waits until Done is called in Stop, so I needed to put the <-node.started in a routine before calling node.Start because this test was getting stuck never moving past start.
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.
Ooof yeah weird piece of code there. It's a bit out of scope, but maybe rename it to Run()
instead of Start()
? Since it doesn't really start and return, it 'runs' all the services in a blocking way.
I've commented and/or addressed remaining comments, let me know if there are remaining issues. |
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.
good work Ed!
lib/babe/babe.go
Outdated
NewServiceIFace(cfg *ServiceConfig) (ServiceIFace, error) | ||
} | ||
|
||
var _ ServiceBuilder = (*Builder)(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.
Why are you using ServiceBuilder
?
Why is using ServiceBuilder
better than using NewServiceIFace
directly?
I think you should be able to using NewServiceIFace
directly
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.
The ServiceBuilder interface was created so that we have an interface for generating mocks for that, mocks for this interface are used in service_test.go Test_nodeBuilder_createBABEService tests. I'm not sure how to generate mocks without an interface.
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 could have used an anonymous function signature instead of an interface. But you would have to manually write a dummy function that implemented that function signature for testing.
I don't think this interface needs to be defined in the babe
package. You could move this interface to be defined in dot
to localise it to nodeBuilder.createBABEServiceWithBuilder
. It doesn't really make sense for the babe
package to have to have an interface for one if its types constructors. Can we change this?
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.
@edwardmack Have you addressed this?
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.
just the moving of the ServiceBuilder
interface to where it's required.
lib/babe/babe.go
Outdated
NewServiceIFace(cfg *ServiceConfig) (ServiceIFace, error) | ||
} | ||
|
||
var _ ServiceBuilder = (*Builder)(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 could have used an anonymous function signature instead of an interface. But you would have to manually write a dummy function that implemented that function signature for testing.
I don't think this interface needs to be defined in the babe
package. You could move this interface to be defined in dot
to localise it to nodeBuilder.createBABEServiceWithBuilder
. It doesn't really make sense for the babe
package to have to have an interface for one if its types constructors. Can we change this?
I've updated to address comments, and moved ServiceBuilder interface to |
got, err := builder.createSystemService(tt.args.cfg, tt.args.service) | ||
assert.ErrorIs(t, err, tt.err) | ||
|
||
// TODO: change this check to assert.Equal after state.Service interface is implemented. |
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 five TODO statements in this file, remove when applicable
Changes
dot
package:build_spec_test.go
,config_test.go
,import_test.go
,node_test.go
,service_test.go
andutils_test.go
Tests
Issues
Primary Reviewer