You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package mock_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. "github.com/tendermint/tendermint/libs/bytes"
  9. "github.com/tendermint/tendermint/rpc/client/mock"
  10. "github.com/tendermint/tendermint/rpc/coretypes"
  11. )
  12. func TestStatus(t *testing.T) {
  13. assert, require := assert.New(t), require.New(t)
  14. m := &mock.StatusMock{
  15. Call: mock.Call{
  16. Response: &coretypes.ResultStatus{
  17. SyncInfo: coretypes.SyncInfo{
  18. LatestBlockHash: bytes.HexBytes("block"),
  19. LatestAppHash: bytes.HexBytes("app"),
  20. LatestBlockHeight: 10,
  21. MaxPeerBlockHeight: 20,
  22. TotalSyncedTime: time.Second,
  23. RemainingTime: time.Minute,
  24. TotalSnapshots: 10,
  25. ChunkProcessAvgTime: time.Duration(10),
  26. SnapshotHeight: 10,
  27. SnapshotChunksCount: 9,
  28. SnapshotChunksTotal: 10,
  29. BackFilledBlocks: 9,
  30. BackFillBlocksTotal: 10,
  31. },
  32. }},
  33. }
  34. r := mock.NewStatusRecorder(m)
  35. require.Equal(0, len(r.Calls))
  36. // make sure response works proper
  37. status, err := r.Status(context.Background())
  38. require.Nil(err, "%+v", err)
  39. assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
  40. assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
  41. assert.EqualValues(20, status.SyncInfo.MaxPeerBlockHeight)
  42. assert.EqualValues(time.Second, status.SyncInfo.TotalSyncedTime)
  43. assert.EqualValues(time.Minute, status.SyncInfo.RemainingTime)
  44. // make sure recorder works properly
  45. require.Equal(1, len(r.Calls))
  46. rs := r.Calls[0]
  47. assert.Equal("status", rs.Name)
  48. assert.Nil(rs.Args)
  49. assert.Nil(rs.Error)
  50. require.NotNil(rs.Response)
  51. st, ok := rs.Response.(*coretypes.ResultStatus)
  52. require.True(ok)
  53. assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
  54. assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
  55. assert.EqualValues(20, st.SyncInfo.MaxPeerBlockHeight)
  56. assert.EqualValues(time.Second, status.SyncInfo.TotalSyncedTime)
  57. assert.EqualValues(time.Minute, status.SyncInfo.RemainingTime)
  58. assert.EqualValues(10, st.SyncInfo.TotalSnapshots)
  59. assert.EqualValues(time.Duration(10), st.SyncInfo.ChunkProcessAvgTime)
  60. assert.EqualValues(10, st.SyncInfo.SnapshotHeight)
  61. assert.EqualValues(9, status.SyncInfo.SnapshotChunksCount)
  62. assert.EqualValues(10, status.SyncInfo.SnapshotChunksTotal)
  63. assert.EqualValues(9, status.SyncInfo.BackFilledBlocks)
  64. assert.EqualValues(10, status.SyncInfo.BackFillBlocksTotal)
  65. }