-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from gatewayd-io/add-benchmarks
Add benchmarks
- Loading branch information
Showing
12 changed files
with
900 additions
and
1 deletion.
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,72 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/knadh/koanf" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestNewConfig tests the NewConfig function. | ||
func TestNewConfig(t *testing.T) { | ||
config := NewConfig( | ||
context.Background(), GlobalConfigFilename, PluginsConfigFilename) | ||
assert.NotNil(t, config) | ||
assert.Equal(t, config.globalConfigFile, GlobalConfigFilename) | ||
assert.Equal(t, config.pluginConfigFile, PluginsConfigFilename) | ||
assert.Equal(t, config.globalDefaults, GlobalConfig{}) | ||
assert.Equal(t, config.pluginDefaults, PluginConfig{}) | ||
assert.Equal(t, config.Global, GlobalConfig{}) | ||
assert.Equal(t, config.Plugin, PluginConfig{}) | ||
assert.Equal(t, config.GlobalKoanf, koanf.New(".")) | ||
assert.Equal(t, config.PluginKoanf, koanf.New(".")) | ||
} | ||
|
||
// TestInitConfig tests the InitConfig function, which practically tests all | ||
// the other functions. | ||
func TestInitConfig(t *testing.T) { | ||
ctx := context.Background() | ||
config := NewConfig(ctx, "../"+GlobalConfigFilename, "../"+PluginsConfigFilename) | ||
config.InitConfig(ctx) | ||
assert.NotNil(t, config.Global) | ||
assert.NotEqual(t, config.Global, GlobalConfig{}) | ||
assert.Contains(t, config.Global.Servers, Default) | ||
assert.NotNil(t, config.Plugin) | ||
assert.NotEqual(t, config.Plugin, PluginConfig{}) | ||
assert.Len(t, config.Plugin.Plugins, 1) | ||
assert.NotNil(t, config.GlobalKoanf) | ||
assert.NotEqual(t, config.GlobalKoanf, koanf.New(".")) | ||
assert.Equal(t, DefaultLogLevel, config.GlobalKoanf.String("loggers.default.level")) | ||
assert.NotNil(t, config.PluginKoanf) | ||
assert.NotEqual(t, config.PluginKoanf, koanf.New(".")) | ||
assert.Equal(t, string(PassDown), config.PluginKoanf.String("verificationPolicy")) | ||
assert.NotNil(t, config.globalDefaults) | ||
assert.NotEqual(t, config.globalDefaults, GlobalConfig{}) | ||
assert.Contains(t, config.globalDefaults.Servers, Default) | ||
assert.NotNil(t, config.pluginDefaults) | ||
assert.NotEqual(t, config.pluginDefaults, PluginConfig{}) | ||
assert.Len(t, config.pluginDefaults.Plugins, 0) | ||
} | ||
|
||
// TestMergeGlobalConfig tests the MergeGlobalConfig function. | ||
func TestMergeGlobalConfig(t *testing.T) { | ||
ctx := context.Background() | ||
config := NewConfig(ctx, "../"+GlobalConfigFilename, "../"+PluginsConfigFilename) | ||
config.InitConfig(ctx) | ||
// The default log level is info. | ||
assert.Equal(t, config.Global.Loggers[Default].Level, DefaultLogLevel) | ||
|
||
// Merge a config that sets the log level to debug. | ||
config.MergeGlobalConfig(ctx, map[string]interface{}{ | ||
"loggers": map[string]interface{}{ | ||
"default": map[string]interface{}{ | ||
"level": "debug", | ||
}, | ||
}, | ||
}) | ||
assert.NotNil(t, config.Global) | ||
assert.NotEqual(t, config.Global, GlobalConfig{}) | ||
// The log level should now be debug. | ||
assert.Equal(t, config.Global.Loggers[Default].Level, "debug") | ||
} |
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,130 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/panjf2000/gnet/v2" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestGetVerificationPolicy tests the GetVerificationPolicy function. | ||
func TestGetVerificationPolicy(t *testing.T) { | ||
pluginConfig := PluginConfig{} | ||
assert.Equal(t, PassDown, pluginConfig.GetVerificationPolicy()) | ||
} | ||
|
||
// TestGetPluginCompatibilityPolicy tests the GetPluginCompatibilityPolicy function. | ||
func TestGetPluginCompatibilityPolicy(t *testing.T) { | ||
pluginConfig := PluginConfig{} | ||
assert.Equal(t, Strict, pluginConfig.GetPluginCompatibilityPolicy()) | ||
} | ||
|
||
// TestGetAcceptancePolicy tests the GetAcceptancePolicy function. | ||
func TestGetAcceptancePolicy(t *testing.T) { | ||
pluginConfig := PluginConfig{} | ||
assert.Equal(t, Accept, pluginConfig.GetAcceptancePolicy()) | ||
} | ||
|
||
// TestGetTerminationPolicy tests the GetTerminationPolicy function. | ||
func TestGetTerminationPolicy(t *testing.T) { | ||
pluginConfig := PluginConfig{} | ||
assert.Equal(t, Stop, pluginConfig.GetTerminationPolicy()) | ||
} | ||
|
||
// TestGetTCPKeepAlivePeriod tests the GetTCPKeepAlivePeriod function. | ||
func TestGetTCPKeepAlivePeriod(t *testing.T) { | ||
client := Client{} | ||
assert.Equal(t, DefaultTCPKeepAlivePeriod, client.GetTCPKeepAlivePeriod()) | ||
} | ||
|
||
// TestGetReceiveDeadline tests the GetReceiveDeadline function. | ||
func TestGetReceiveDeadline(t *testing.T) { | ||
client := Client{} | ||
assert.Equal(t, time.Duration(0), client.GetReceiveDeadline()) | ||
} | ||
|
||
// TestGetReceiveTimeout tests the GetReceiveTimeout function. | ||
func TestGetReceiveTimeout(t *testing.T) { | ||
client := Client{} | ||
assert.Equal(t, time.Duration(0), client.GetReceiveTimeout()) | ||
} | ||
|
||
// TestGetSendDeadline tests the GetSendDeadline function. | ||
func TestGetSendDeadline(t *testing.T) { | ||
client := Client{} | ||
assert.Equal(t, time.Duration(0), client.GetSendDeadline()) | ||
} | ||
|
||
// TestGetReceiveChunkSize tests the GetReceiveChunkSize function. | ||
func TestGetReceiveChunkSize(t *testing.T) { | ||
client := Client{} | ||
assert.Equal(t, DefaultChunkSize, client.GetReceiveChunkSize()) | ||
} | ||
|
||
// TestGetHealthCheckPeriod tests the GetHealthCheckPeriod function. | ||
func TestGetHealthCheckPeriod(t *testing.T) { | ||
proxy := Proxy{} | ||
assert.Equal(t, DefaultHealthCheckPeriod, proxy.GetHealthCheckPeriod()) | ||
} | ||
|
||
// TestGetTickInterval tests the GetTickInterval function. | ||
func TestGetTickInterval(t *testing.T) { | ||
server := Server{} | ||
assert.Equal(t, DefaultTickInterval, server.GetTickInterval()) | ||
} | ||
|
||
// TestGetLoadBalancer tests the GetLoadBalancer function. | ||
func TestGetLoadBalancer(t *testing.T) { | ||
server := Server{} | ||
assert.Equal(t, gnet.RoundRobin, server.GetLoadBalancer()) | ||
} | ||
|
||
// TestGetTCPNoDelay tests the GetTCPNoDelay function. | ||
func TestGetTCPNoDelay(t *testing.T) { | ||
server := Server{} | ||
assert.Equal(t, gnet.TCPDelay, server.GetTCPNoDelay()) | ||
} | ||
|
||
// TestGetSize tests the GetSize function. | ||
func TestGetSize(t *testing.T) { | ||
pool := Pool{} | ||
assert.Equal(t, DefaultPoolSize, pool.GetSize()) | ||
} | ||
|
||
// TestGetOutput tests the GetOutput function. | ||
func TestGetOutput(t *testing.T) { | ||
logger := Logger{} | ||
assert.Equal(t, []LogOutput{Console}, logger.GetOutput()) | ||
} | ||
|
||
// TestGetTimeFormat tests the GetTimeFormat function. | ||
func TestGetTimeFormat(t *testing.T) { | ||
logger := Logger{} | ||
assert.Equal(t, zerolog.TimeFormatUnix, logger.GetTimeFormat()) | ||
} | ||
|
||
// TestGetConsoleTimeFormat tests the GetConsoleTimeFormat function. | ||
func TestGetConsoleTimeFormat(t *testing.T) { | ||
logger := Logger{} | ||
assert.Equal(t, time.RFC3339, logger.GetConsoleTimeFormat()) | ||
} | ||
|
||
// TestGetLevel tests the GetLevel function. | ||
func TestGetLevel(t *testing.T) { | ||
logger := Logger{} | ||
assert.Equal(t, zerolog.InfoLevel, logger.GetLevel()) | ||
} | ||
|
||
// TestGetPlugins tests the GetPlugins function. | ||
func TestGetPlugins(t *testing.T) { | ||
plugin := Plugin{Name: "plugin1"} | ||
pluginConfig := PluginConfig{Plugins: []Plugin{plugin}} | ||
assert.Equal(t, []Plugin{plugin}, pluginConfig.GetPlugins("plugin1")) | ||
} | ||
|
||
// TestGetDefaultConfigFilePath tests the GetDefaultConfigFilePath function. | ||
func TestGetDefaultConfigFilePath(t *testing.T) { | ||
assert.Equal(t, GlobalConfigFilename, GetDefaultConfigFilePath(GlobalConfigFilename)) | ||
} |
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,18 @@ | ||
package config | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestVersionInfo tests the VersionInfo function. | ||
func TestVersionInfo(t *testing.T) { | ||
versionInfo := VersionInfo() | ||
assert.Contains(t, versionInfo, "GatewayD") | ||
assert.Contains(t, versionInfo, "0.0.0") | ||
assert.Contains(t, versionInfo, "go") | ||
assert.Contains(t, versionInfo, runtime.GOOS) | ||
assert.Contains(t, versionInfo, runtime.GOARCH) | ||
} |
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.