-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into aptos-init__csa-key-auth
- Loading branch information
Showing
9 changed files
with
299 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package chainlink | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/config/toml" | ||
"github.com/smartcontractkit/chainlink/v2/core/static" | ||
) | ||
|
||
func TestTelemetryConfig_Enabled(t *testing.T) { | ||
trueVal := true | ||
falseVal := false | ||
|
||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected bool | ||
}{ | ||
{"EnabledTrue", toml.Telemetry{Enabled: &trueVal}, true}, | ||
{"EnabledFalse", toml.Telemetry{Enabled: &falseVal}, false}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.Equal(t, tt.expected, tc.Enabled()) | ||
}) | ||
} | ||
} | ||
|
||
func TestTelemetryConfig_InsecureConnection(t *testing.T) { | ||
trueVal := true | ||
falseVal := false | ||
|
||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected bool | ||
}{ | ||
{"InsecureConnectionTrue", toml.Telemetry{InsecureConnection: &trueVal}, true}, | ||
{"InsecureConnectionFalse", toml.Telemetry{InsecureConnection: &falseVal}, false}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.Equal(t, tt.expected, tc.InsecureConnection()) | ||
}) | ||
} | ||
} | ||
|
||
func TestTelemetryConfig_CACertFile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected string | ||
}{ | ||
{"CACertFileSet", toml.Telemetry{CACertFile: ptr("test.pem")}, "test.pem"}, | ||
{"CACertFileNil", toml.Telemetry{CACertFile: nil}, ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.Equal(t, tt.expected, tc.CACertFile()) | ||
}) | ||
} | ||
} | ||
|
||
func TestTelemetryConfig_OtelExporterGRPCEndpoint(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected string | ||
}{ | ||
{"EndpointSet", toml.Telemetry{Endpoint: ptr("localhost:4317")}, "localhost:4317"}, | ||
{"EndpointNil", toml.Telemetry{Endpoint: nil}, ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.Equal(t, tt.expected, tc.OtelExporterGRPCEndpoint()) | ||
}) | ||
} | ||
} | ||
|
||
func TestTelemetryConfig_ResourceAttributes(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected map[string]string | ||
}{ | ||
{ | ||
"DefaultAttributes", | ||
toml.Telemetry{ResourceAttributes: nil}, | ||
map[string]string{ | ||
"service.name": "chainlink", | ||
"service.version": static.Version, | ||
}, | ||
}, | ||
{ | ||
"CustomAttributes", | ||
toml.Telemetry{ResourceAttributes: map[string]string{"custom.key": "custom.value"}}, | ||
map[string]string{ | ||
"service.name": "chainlink", | ||
"service.version": static.Version, | ||
"custom.key": "custom.value", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.Equal(t, tt.expected, tc.ResourceAttributes()) | ||
}) | ||
} | ||
} | ||
|
||
func TestTelemetryConfig_TraceSampleRatio(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
telemetry toml.Telemetry | ||
expected float64 | ||
}{ | ||
{"TraceSampleRatioSet", toml.Telemetry{TraceSampleRatio: ptrFloat(0.5)}, 0.5}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc := telemetryConfig{s: tt.telemetry} | ||
assert.InEpsilon(t, tt.expected, tc.TraceSampleRatio(), 0.0001) | ||
}) | ||
} | ||
} | ||
|
||
func ptrFloat(f float64) *float64 { | ||
return &f | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.