-
Notifications
You must be signed in to change notification settings - Fork 124
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 #1980
Conversation
I see a lot of integration tests deltas, is this expected? Did you maybe branch off your other integration tests PR?
JSON Marshal will fail if you try to marshal e.g. a function/channel. Maybe add some dummy function field to your
Have a file at the same path 😉 Example
Why would we care about the pointer address?
Shouldn't it cleanup even when there is no error? 🤔 Other general comments
|
I did branch off my other integration tests PR, is this a bad idea? Whats the best way to work on stuff that depends on other stuff you've done. I've gotten into git branch trouble before, so I'm open to suggestions of best way to organize this.
I'm no longer sure I need to test for this since the struct passed to this function insures it will not receive a function/channel.
I wasn't able to create condition where
Good point, I've updated tests to compare returned values.
Yes, good point, I've updated this.
Updated. |
Codecov Report
@@ Coverage Diff @@
## development #1980 +/- ##
===============================================
+ Coverage 61.34% 61.93% +0.59%
===============================================
Files 203 203
Lines 27348 27400 +52
===============================================
+ Hits 16776 16970 +194
+ Misses 8699 8558 -141
+ Partials 1873 1872 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I'd suggest you point this PR to that other branch you branched out from, merge the second one (this one) first and then the other branch (the first one) in development. And yes don't worry too much about impossible to reproduce errors 😄 I'll mess around with |
Can you change the base branch of this PR to the other branch you moved the integration tests too? It'll make the diff easier to read. |
}{ | ||
{ | ||
name: "normal conditions", | ||
fields: fields{genesis: &genesis.Genesis{Name: "test"}}, |
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 add more tests to test the other attributes of genesis.Genesis
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.
added.
I wouldn't worry about trying to test coverage up to 100%. It's not really necessary to test |
dot/node.go
Outdated
@@ -180,7 +180,7 @@ func NodeInitialized(basepath string) bool { | |||
} | |||
|
|||
// LoadGlobalNodeName returns the stored global node name from database | |||
func LoadGlobalNodeName(basepath string) (nodename string, err error) { | |||
func LoadGlobalNodeName(basepath string) (string, error) { |
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.
Please let's use named returned values, it's really useful for readers/documentation.
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.
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("createCoreService() got = %v, want %v", got, tt.want) | ||
if tt.want != nil { | ||
assert.NotNil(t, got) |
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 assert it's nil if we expect it to be nil as well 🤔 ?
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 idea, added.
dot/services_test.go
Outdated
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_createDigestHandler(t *testing.T) { | ||
cfg := NewTestConfig(t) | ||
require.NotNil(t, cfg) |
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.
nit I don't think this NotNil is really required since (afaik) we are asserting something from the test (NewTestConfig
). Same for below checks as well. Although if these helper functions do use some production code, maybe do the assertion inside them since you are already passing t
to them.
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.
Ok, removed.
dot/services_test.go
Outdated
st: stateSrvc, | ||
code: []byte(`fake code`), | ||
}, | ||
err: errors.New("failed to create runtime executor: Failed to instantiate the module:\n compile error: Validation error \"Bad magic number\""), |
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.
Is it us or the runtime returning an error with \n
?
lib/babe/verify.go
Outdated
switch blockState.(type) { | ||
case *state.BlockState: | ||
if blockState == (*state.BlockState)(nil) { | ||
return nil, errNilBlockState | ||
} | ||
default: | ||
if reflect.ValueOf(blockState).IsNil() { | ||
return nil, errNilBlockState | ||
} | ||
} |
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.
supernit to reduce code duplication if we add more cases 😉
switch blockState.(type) { | |
case *state.BlockState: | |
if blockState == (*state.BlockState)(nil) { | |
return nil, errNilBlockState | |
} | |
default: | |
if reflect.ValueOf(blockState).IsNil() { | |
return nil, errNilBlockState | |
} | |
} | |
var isNil bool | |
switch blockState.(type) { | |
case *state.BlockState: | |
isNil = blockState == (*state.BlockState)(nil) | |
default: | |
isNil = reflect.ValueOf(blockState).IsNil() | |
} | |
if isNil { | |
return nil, errNilBlockState | |
} |
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.
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.1 to 2.5.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v2.4.1...v2.5.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
//<<<<<<< HEAD | ||
//======= | ||
// | ||
// bs.genesis.ChainType = expectedChainType | ||
// bs.genesis.Properties = expectedProperties | ||
// | ||
// require.NoError(t, err) | ||
// | ||
// // confirm human-readable 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.
remove commented out block
// gen := new(genesis.Genesis) | ||
// err = json.Unmarshal(genesisBytes, gen) | ||
// require.NoError(t, err) | ||
//>>>>>>> development |
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
return node, nil | ||
} | ||
|
||
//InitKeystore to initialize node keystore |
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.
//InitKeystore to initialize node keystore | |
// InitKeystore initialised the node's keystore |
@@ -41,9 +48,87 @@ type Node struct { | |||
started chan struct{} | |||
} | |||
|
|||
//go:generate mockgen -source=node.go -destination=mock_node_test.go -package=$GOPACKAGE | |||
|
|||
type newNodeIface 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.
nice! I like this interface a lot, maybe name it nodeBuilder
or nodeCreator
or something like that?
var isNilBlock bool | ||
switch blockState.(type) { | ||
case *state.BlockState: | ||
isNilBlock = blockState == (*state.BlockState)(nil) | ||
default: | ||
isNilBlock = reflect.ValueOf(blockState).IsNil() | ||
} | ||
if isNilBlock { | ||
return nil, errNilBlockState | ||
} | ||
|
||
if epochState == nil { | ||
var isNilEpoch bool | ||
switch epochState.(type) { | ||
case *state.EpochState: | ||
isNilEpoch = epochState == (*state.EpochState)(nil) | ||
default: | ||
isNilEpoch = reflect.ValueOf(epochState).IsNil() | ||
} | ||
if isNilEpoch { |
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.
do we ned this isNilBlock = blockState == (*state.BlockState)(nil)
or does reflect.ValueOf(blockState).IsNil()
evaluate to the same thing? I'd rather not have the (*state.BlockState)
type assertion if possible
@@ -403,7 +403,7 @@ func (bt *BlockTree) StoreRuntime(hash common.Hash, in runtime.Instance) { | |||
// GetBlockRuntime returns block runtime for corresponding block hash. | |||
func (bt *BlockTree) GetBlockRuntime(hash common.Hash) (runtime.Instance, error) { | |||
ins, ok := bt.runtime.Load(hash) | |||
if !ok { | |||
if !ok || ins == 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.
is ins == nil
a case that happens? that seems concerning to me lol
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.
very nice work! just a few comments, but the tests look good to me :D
closed, replaced by PR #2112 |
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