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.

89 lines
2.3 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 core
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/config"
  7. "github.com/tendermint/tendermint/internal/p2p"
  8. "github.com/tendermint/tendermint/libs/log"
  9. rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
  10. )
  11. func TestUnsafeDialSeeds(t *testing.T) {
  12. sw := p2p.MakeSwitch(config.DefaultP2PConfig(), 1, "testing", "123.123.123",
  13. func(n int, sw *p2p.Switch) *p2p.Switch { return sw }, log.TestingLogger())
  14. err := sw.Start()
  15. require.NoError(t, err)
  16. t.Cleanup(func() {
  17. if err := sw.Stop(); err != nil {
  18. t.Error(err)
  19. }
  20. })
  21. env := &Environment{}
  22. env.Logger = log.TestingLogger()
  23. env.P2PPeers = sw
  24. testCases := []struct {
  25. seeds []string
  26. isErr bool
  27. }{
  28. {[]string{}, true},
  29. {[]string{"d51fb70907db1c6c2d5237e78379b25cf1a37ab4@127.0.0.1:41198"}, false},
  30. {[]string{"127.0.0.1:41198"}, true},
  31. }
  32. for _, tc := range testCases {
  33. res, err := env.UnsafeDialSeeds(&rpctypes.Context{}, tc.seeds)
  34. if tc.isErr {
  35. assert.Error(t, err)
  36. } else {
  37. assert.NoError(t, err)
  38. assert.NotNil(t, res)
  39. }
  40. }
  41. }
  42. func TestUnsafeDialPeers(t *testing.T) {
  43. sw := p2p.MakeSwitch(config.DefaultP2PConfig(), 1, "testing", "123.123.123",
  44. func(n int, sw *p2p.Switch) *p2p.Switch { return sw }, log.TestingLogger())
  45. sw.SetAddrBook(&p2p.AddrBookMock{
  46. Addrs: make(map[string]struct{}),
  47. OurAddrs: make(map[string]struct{}),
  48. PrivateAddrs: make(map[string]struct{}),
  49. })
  50. err := sw.Start()
  51. require.NoError(t, err)
  52. t.Cleanup(func() {
  53. if err := sw.Stop(); err != nil {
  54. t.Error(err)
  55. }
  56. })
  57. env := &Environment{}
  58. env.Logger = log.TestingLogger()
  59. env.P2PPeers = sw
  60. testCases := []struct {
  61. peers []string
  62. persistence, unconditional, private bool
  63. isErr bool
  64. }{
  65. {[]string{}, false, false, false, true},
  66. {[]string{"d51fb70907db1c6c2d5237e78379b25cf1a37ab4@127.0.0.1:41198"}, true, true, true, false},
  67. {[]string{"127.0.0.1:41198"}, true, true, false, true},
  68. }
  69. for _, tc := range testCases {
  70. res, err := env.UnsafeDialPeers(&rpctypes.Context{}, tc.peers, tc.persistence, tc.unconditional, tc.private)
  71. if tc.isErr {
  72. assert.Error(t, err)
  73. } else {
  74. assert.NoError(t, err)
  75. assert.NotNil(t, res)
  76. }
  77. }
  78. }