mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 01:13:40 +01:00
chore: Reformat some code and docs
This commit is contained in:
parent
2b9d3e99d3
commit
6d64c3c250
10
README.md
10
README.md
@ -314,11 +314,11 @@ endpoints:
|
|||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
```
|
```
|
||||||
|
|
||||||
This example shows how you can use a `custom DNS Resolver`:
|
This example shows how you can specify a custom DNS resolver:
|
||||||
```yaml
|
```yaml
|
||||||
endpoints:
|
endpoints:
|
||||||
- name: website
|
- name: with-custom-dns-resolver
|
||||||
url: "https://your.health.api/getHealth"
|
url: "https://your.health.api/health"
|
||||||
client:
|
client:
|
||||||
dns-resolver: "tcp://1.1.1.1:53"
|
dns-resolver: "tcp://1.1.1.1:53"
|
||||||
conditions:
|
conditions:
|
||||||
@ -328,8 +328,8 @@ endpoints:
|
|||||||
This example shows how you can use the `client.oauth2` configuration to query a backend API with `Bearer token`:
|
This example shows how you can use the `client.oauth2` configuration to query a backend API with `Bearer token`:
|
||||||
```yaml
|
```yaml
|
||||||
endpoints:
|
endpoints:
|
||||||
- name: website
|
- name: with-custom-oauth2
|
||||||
url: "https://your.health.api/getHealth"
|
url: "https://your.health.api/health"
|
||||||
client:
|
client:
|
||||||
oauth2:
|
oauth2:
|
||||||
token-url: https://your-token-server/token
|
token-url: https://your-token-server/token
|
||||||
|
@ -58,44 +58,42 @@ func TestPing(t *testing.T) {
|
|||||||
|
|
||||||
func TestDNSResolverConfig(t *testing.T) {
|
func TestDNSResolverConfig(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
resolver string
|
dnsResolver string
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Valid resolver",
|
name: "valid resolver",
|
||||||
args: args{
|
args: args{
|
||||||
resolver: "tcp://1.1.1.1:53",
|
dnsResolver: "tcp://1.1.1.1:53",
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid resolver address/port",
|
name: "invalid resolver port",
|
||||||
args: args{
|
args: args{
|
||||||
resolver: "tcp://127.0.0.1:99999",
|
dnsResolver: "tcp://127.0.0.1:99999",
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid resolver format",
|
name: "invalid resolver format",
|
||||||
args: args{
|
args: args{
|
||||||
resolver: "foobaz",
|
dnsResolver: "foobar",
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
DNSResolver: tt.args.resolver,
|
DNSResolver: tt.args.dnsResolver,
|
||||||
}
|
}
|
||||||
client := GetHTTPClient(cfg)
|
client := GetHTTPClient(cfg)
|
||||||
_, err := client.Get("https://www.google.com")
|
_, err := client.Get("https://example.org")
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("TestDNSResolverConfig err=%v, wantErr=%v", err, tt.wantErr)
|
t.Errorf("TestDNSResolverConfig err=%v, wantErr=%v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
@ -214,16 +212,13 @@ func TestCanCreateTCPConnection(t *testing.T) {
|
|||||||
// performs a Client Credentials OAuth2 flow and adds the obtained token as a `Authorization`
|
// performs a Client Credentials OAuth2 flow and adds the obtained token as a `Authorization`
|
||||||
// header to all outgoing HTTP calls.
|
// header to all outgoing HTTP calls.
|
||||||
func TestHttpClientProvidesOAuth2BearerToken(t *testing.T) {
|
func TestHttpClientProvidesOAuth2BearerToken(t *testing.T) {
|
||||||
|
|
||||||
defer InjectHTTPClient(nil)
|
defer InjectHTTPClient(nil)
|
||||||
|
|
||||||
oAuth2Config := &OAuth2Config{
|
oAuth2Config := &OAuth2Config{
|
||||||
ClientID: "00000000-0000-0000-0000-000000000000",
|
ClientID: "00000000-0000-0000-0000-000000000000",
|
||||||
ClientSecret: "secretsauce",
|
ClientSecret: "secretsauce",
|
||||||
TokenURL: "https://token-server.local/token",
|
TokenURL: "https://token-server.local/token",
|
||||||
Scopes: []string{"https://application.local/.default"},
|
Scopes: []string{"https://application.local/.default"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mockHttpClient := &http.Client{
|
mockHttpClient := &http.Client{
|
||||||
Transport: test.MockRoundTripper(func(r *http.Request) *http.Response {
|
Transport: test.MockRoundTripper(func(r *http.Request) *http.Response {
|
||||||
|
|
||||||
@ -239,7 +234,6 @@ func TestHttpClientProvidesOAuth2BearerToken(t *testing.T) {
|
|||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// to verify the headers were sent as expected, we echo them back in the
|
// to verify the headers were sent as expected, we echo them back in the
|
||||||
// `X-Org-Authorization` header and check if the token value matches our
|
// `X-Org-Authorization` header and check if the token value matches our
|
||||||
// mocked `token-server` response
|
// mocked `token-server` response
|
||||||
@ -252,24 +246,19 @@ func TestHttpClientProvidesOAuth2BearerToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
mockHttpClientWithOAuth := configureOAuth2(mockHttpClient, *oAuth2Config)
|
mockHttpClientWithOAuth := configureOAuth2(mockHttpClient, *oAuth2Config)
|
||||||
InjectHTTPClient(mockHttpClientWithOAuth)
|
InjectHTTPClient(mockHttpClientWithOAuth)
|
||||||
|
|
||||||
request, err := http.NewRequest(http.MethodPost, "http://127.0.0.1:8282", http.NoBody)
|
request, err := http.NewRequest(http.MethodPost, "http://127.0.0.1:8282", http.NoBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected no error, got", err.Error())
|
t.Error("expected no error, got", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := mockHttpClientWithOAuth.Do(request)
|
response, err := mockHttpClientWithOAuth.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected no error, got", err.Error())
|
t.Error("expected no error, got", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.Header == nil {
|
if response.Header == nil {
|
||||||
t.Error("expected response headers, but got nil")
|
t.Error("expected response headers, but got nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
// the mock response echos the Authorization header used in the request back
|
// the mock response echos the Authorization header used in the request back
|
||||||
// to us as `X-Org-Authorization` header, we check here if the value matches
|
// to us as `X-Org-Authorization` header, we check here if the value matches
|
||||||
// our expected token `secret-token`
|
// our expected token `secret-token`
|
||||||
|
Loading…
Reference in New Issue
Block a user