Skip to content

Commit

Permalink
update tests as per changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed May 22, 2024
1 parent e1d21b5 commit 7114776
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ type JSONLogRequest struct {
Input string `json:"input"`
Address string `json:"address"`
Error string `json:"error"`
Kind string `json:"kind"`
Kind string `json:"kind,omitempty"`
Attrs interface{} `json:"attrs,omitempty"`
}

Expand All @@ -321,7 +321,6 @@ func (w *StandardWriter) Request(templatePath, input, requestType string, reques
Template: templatePath,
Input: input,
Type: requestType,
Kind: errkit.ErrKindUnknown.String(),
}
parsed, _ := urlutil.ParseAbsoluteURL(input, false)
if parsed != nil {
Expand All @@ -341,6 +340,7 @@ func (w *StandardWriter) Request(templatePath, input, requestType string, reques
if errX == nil {
request.Error = "none"
} else {
request.Kind = errkit.ErrKindUnknown.String()
var cause error
if len(errX.Errors()) > 1 {
cause = errX.Errors()[0]
Expand Down
4 changes: 2 additions & 2 deletions pkg/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestStandardWriterRequest(t *testing.T) {
require.NoError(t, err)
w.Request("path", "input", "http", nil)

require.Equal(t, `{"template":"path","input":"input","error":"none","type":"http"}`, traceWriter.String())
require.Equal(t, `{"template":"path","type":"http","input":"input","address":"input:","error":"none"}`, traceWriter.String())
require.Empty(t, errorWriter.String())
})

Expand All @@ -47,7 +47,7 @@ func TestStandardWriterRequest(t *testing.T) {
fmt.Errorf("GET https://example.com/tcpconfig.html/tcpconfig.html giving up after 2 attempts: %w", errors.New("context deadline exceeded (Client.Timeout exceeded while awaiting headers)")),
)

require.Equal(t, `{"template":"misconfiguration/tcpconfig.yaml","input":"https://example.com/tcpconfig.html","error":"context deadline exceeded (Client.Timeout exceeded while awaiting headers)","type":"http"}`, errorWriter.String())
require.Equal(t, `{"template":"misconfiguration/tcpconfig.yaml","type":"http","input":"https://example.com/tcpconfig.html","address":"example.com:443","error":"context deadline exceeded (Client.Timeout exceeded while awaiting headers)","kind":"unknown-error"}`, errorWriter.String())
})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/protocols/common/contextargs/metainput.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (metaInput *MetaInput) Address() string {
var hostname, port string
target, err := urlutil.ParseAbsoluteURL(metaInput.Target(), false)
if err != nil {
err = nil
if metaInput.CustomIP == "" {
// since this is used in hosterrorscache we add a random id
// which will never be used to avoid skipping valid targets
Expand Down
10 changes: 6 additions & 4 deletions pkg/protocols/common/hosterrorscache/hosterrorscache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ func TestCacheMarkFailed(t *testing.T) {

tests := []struct {
host string
expected int
expected int32
}{
{"http://example.com:80", 1},
{"example.com:80", 2},
{"example.com", 1},
// earlier if port is not provided then port was omitted
// but from now it will default to appropriate http scheme based port with 80 as default
{"example.com:443", 1},
}

for _, test := range tests {
normalizedCacheValue := cache.normalizeCacheValue(test.host)
normalizedCacheValue := cache.GetKeyFromContext(newCtxArgs(test.host), nil)
cache.MarkFailed(newCtxArgs(test.host), fmt.Errorf("no address found for host"))
failedTarget, err := cache.failedTargets.Get(normalizedCacheValue)
require.Nil(t, err)
Expand All @@ -104,7 +106,7 @@ func TestCacheMarkFailedConcurrent(t *testing.T) {
}{
{"http://example.com:80", 200},
{"example.com:80", 200},
{"example.com", 100},
{"example.com:443", 100},
}

// the cache is not atomic during items creation, so we pre-create them with counter to zero
Expand Down

0 comments on commit 7114776

Please sign in to comment.