mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-04 04:04:00 +00:00
* ci: Fix linter complaint (#9645)
Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.
---
#### PR checklist
- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
documentation updates needed
(cherry picked from commit 83b7f4ad5b)
# Conflicts:
# .github/workflows/lint.yml
# .golangci.yml
# cmd/tendermint/commands/debug/util.go
* Resolve conflicts
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* ci: Sync golangci-lint config with main
Minus the spelling configuration that restricts spelling to US English
only.
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* make format
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove usage of deprecated io/ioutil package
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Remove unused mockBlockStore
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* blockchain/v2: Remove unused method
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* Bulk fix lints
Signed-off-by: Thane Thomson <connect@thanethomson.com>
* lint: Ignore auto-generated query PEG
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package client
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHTTPClientMakeHTTPDialer(t *testing.T) {
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = w.Write([]byte("Hi!\n"))
|
|
})
|
|
ts := httptest.NewServer(handler)
|
|
defer ts.Close()
|
|
|
|
tsTLS := httptest.NewTLSServer(handler)
|
|
defer tsTLS.Close()
|
|
// This silences a TLS handshake error, caused by the dialer just immediately
|
|
// disconnecting, which we can just ignore.
|
|
tsTLS.Config.ErrorLog = log.New(io.Discard, "", 0)
|
|
|
|
for _, testURL := range []string{ts.URL, tsTLS.URL} {
|
|
u, err := newParsedURL(testURL)
|
|
require.NoError(t, err)
|
|
dialFn, err := makeHTTPDialer(testURL)
|
|
require.Nil(t, err)
|
|
|
|
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
|
|
require.NoError(t, err)
|
|
require.NotNil(t, addr)
|
|
}
|
|
}
|
|
|
|
func Test_parsedURL(t *testing.T) {
|
|
type test struct {
|
|
url string
|
|
expectedURL string
|
|
expectedHostWithPath string
|
|
expectedDialAddress string
|
|
}
|
|
|
|
tests := map[string]test{
|
|
"unix endpoint": {
|
|
url: "unix:///tmp/test",
|
|
expectedURL: "unix://.tmp.test",
|
|
expectedHostWithPath: "/tmp/test",
|
|
expectedDialAddress: "/tmp/test",
|
|
},
|
|
|
|
"http endpoint": {
|
|
url: "https://example.com",
|
|
expectedURL: "https://example.com",
|
|
expectedHostWithPath: "example.com",
|
|
expectedDialAddress: "example.com",
|
|
},
|
|
|
|
"http endpoint with port": {
|
|
url: "https://example.com:8080",
|
|
expectedURL: "https://example.com:8080",
|
|
expectedHostWithPath: "example.com:8080",
|
|
expectedDialAddress: "example.com:8080",
|
|
},
|
|
|
|
"http path routed endpoint": {
|
|
url: "https://example.com:8080/rpc",
|
|
expectedURL: "https://example.com:8080/rpc",
|
|
expectedHostWithPath: "example.com:8080/rpc",
|
|
expectedDialAddress: "example.com:8080",
|
|
},
|
|
}
|
|
|
|
for name, tt := range tests {
|
|
tt := tt // suppressing linter
|
|
t.Run(name, func(t *testing.T) {
|
|
parsed, err := newParsedURL(tt.url)
|
|
require.NoError(t, err)
|
|
require.Equal(t, tt.expectedDialAddress, parsed.GetDialAddress())
|
|
require.Equal(t, tt.expectedURL, parsed.GetTrimmedURL())
|
|
require.Equal(t, tt.expectedHostWithPath, parsed.GetHostWithPath())
|
|
})
|
|
}
|
|
}
|