-
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.
* Add test for act/buitins.go * Add pgx to allow list of tests * Update test to cover more lines * Add test for embed_swagger.go * Add test for api/healthcheck.go * Test Execute function * Redirect stdout and stderr to buffer * Create a directory before generating markdown files * Add test for cmd/gen_docs.go * Gofumpt * Fix magic number * Fix output message * Test multi-tenant config * Update config function signatures to return errors instead of log.Fatal that runs os.Exit * Add test for config validation * Fix linter errors * Add test for missing config file * Add more tests for config package * Add tests for syslog and rsyslog * Add tests for hclog log level * Test hclog logging with different levels * Add test for header bypass response writer * Test removal of plugin from metrics merger and start/stop of the merger scheduler * Add test for network/conn_wrapper.go * Address linter issues * Remove read/write test * Test more plugin registry function * Add test for OTLP tracer
- Loading branch information
Showing
27 changed files
with
856 additions
and
92 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,131 @@ | ||
package act | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkAct "github.com/gatewayd-io/gatewayd-plugin-sdk/act" | ||
"github.com/gatewayd-io/gatewayd-plugin-sdk/databases/postgres" | ||
gerr "github.com/gatewayd-io/gatewayd/errors" | ||
"github.com/jackc/pgx/v5/pgproto3" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Terminate_Action(t *testing.T) { | ||
response, err := (&pgproto3.Terminate{}).Encode( | ||
postgres.ErrorResponse( | ||
"Request terminated", | ||
"ERROR", | ||
"42000", | ||
"Policy terminated the request", | ||
), | ||
) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
params []sdkAct.Parameter | ||
result any | ||
err error | ||
}{ | ||
{ | ||
params: []sdkAct.Parameter{}, | ||
result: nil, | ||
err: gerr.ErrLoggerRequired, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: nil, | ||
}, | ||
}, | ||
result: nil, | ||
err: gerr.ErrLoggerRequired, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: zerolog.New(nil), | ||
}, | ||
}, | ||
result: true, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: zerolog.New(nil), | ||
}, | ||
{ | ||
Key: ResultKey, | ||
Value: nil, | ||
}, | ||
}, | ||
result: true, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: zerolog.New(nil), | ||
}, | ||
{ | ||
Key: ResultKey, | ||
Value: map[string]any{}, | ||
}, | ||
}, | ||
result: map[string]any{"response": response}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run("Test_Terminate_Action", func(t *testing.T) { | ||
result, err := Terminate(nil, test.params...) | ||
assert.ErrorIs(t, err, test.err) | ||
assert.Equal(t, result, test.result) | ||
}) | ||
} | ||
} | ||
|
||
func Test_Log_Action(t *testing.T) { | ||
tests := []struct { | ||
params []sdkAct.Parameter | ||
result any | ||
err error | ||
}{ | ||
{ | ||
params: []sdkAct.Parameter{}, | ||
result: nil, | ||
err: gerr.ErrLoggerRequired, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: nil, | ||
}, | ||
}, | ||
result: nil, | ||
err: gerr.ErrLoggerRequired, | ||
}, | ||
{ | ||
params: []sdkAct.Parameter{ | ||
{ | ||
Key: LoggerKey, | ||
Value: zerolog.New(nil), | ||
}, | ||
}, | ||
result: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run("Test_Log_Action", func(t *testing.T) { | ||
result, err := Log(nil, test.params...) | ||
assert.ErrorIs(t, err, test.err) | ||
assert.Equal(t, result, test.result) | ||
}) | ||
} | ||
} |
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,11 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_IsSwaggerEmbedded(t *testing.T) { | ||
assert.False(t, IsSwaggerEmbedded()) | ||
} |
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,94 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/gatewayd-io/gatewayd/act" | ||
"github.com/gatewayd-io/gatewayd/config" | ||
"github.com/gatewayd-io/gatewayd/network" | ||
"github.com/gatewayd-io/gatewayd/plugin" | ||
"github.com/gatewayd-io/gatewayd/pool" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc/health/grpc_health_v1" | ||
) | ||
|
||
func Test_Healthchecker(t *testing.T) { | ||
clientConfig := &config.Client{ | ||
Network: config.DefaultNetwork, | ||
Address: config.DefaultAddress, | ||
} | ||
client := network.NewClient(context.TODO(), clientConfig, zerolog.Logger{}, nil) | ||
newPool := pool.NewPool(context.TODO(), 1) | ||
require.NotNil(t, newPool) | ||
assert.Nil(t, newPool.Put(client.ID, client)) | ||
|
||
proxy := network.NewProxy( | ||
context.TODO(), | ||
network.Proxy{ | ||
AvailableConnections: newPool, | ||
HealthCheckPeriod: config.DefaultHealthCheckPeriod, | ||
ClientConfig: &config.Client{ | ||
Network: config.DefaultNetwork, | ||
Address: config.DefaultAddress, | ||
}, | ||
Logger: zerolog.Logger{}, | ||
PluginTimeout: config.DefaultPluginTimeout, | ||
}, | ||
) | ||
|
||
actRegistry := act.NewActRegistry( | ||
act.Registry{ | ||
Signals: act.BuiltinSignals(), | ||
Policies: act.BuiltinPolicies(), | ||
Actions: act.BuiltinActions(), | ||
DefaultPolicyName: config.DefaultPolicy, | ||
PolicyTimeout: config.DefaultPolicyTimeout, | ||
DefaultActionTimeout: config.DefaultActionTimeout, | ||
Logger: zerolog.Logger{}, | ||
}) | ||
|
||
pluginRegistry := plugin.NewRegistry( | ||
context.TODO(), | ||
plugin.Registry{ | ||
ActRegistry: actRegistry, | ||
Compatibility: config.Loose, | ||
Logger: zerolog.Logger{}, | ||
DevMode: true, | ||
}, | ||
) | ||
|
||
server := network.NewServer( | ||
context.TODO(), | ||
network.Server{ | ||
Network: config.DefaultNetwork, | ||
Address: config.DefaultAddress, | ||
TickInterval: config.DefaultTickInterval, | ||
Options: network.Option{ | ||
EnableTicker: false, | ||
}, | ||
Proxy: proxy, | ||
Logger: zerolog.Logger{}, | ||
PluginRegistry: pluginRegistry, | ||
PluginTimeout: config.DefaultPluginTimeout, | ||
HandshakeTimeout: config.DefaultHandshakeTimeout, | ||
}, | ||
) | ||
|
||
healthchecker := HealthChecker{ | ||
Servers: map[string]*network.Server{ | ||
config.Default: server, | ||
}, | ||
} | ||
assert.NotNil(t, healthchecker) | ||
hcr, err := healthchecker.Check(context.TODO(), &grpc_health_v1.HealthCheckRequest{}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, hcr) | ||
assert.Equal(t, grpc_health_v1.HealthCheckResponse_NOT_SERVING, hcr.GetStatus()) | ||
|
||
err = healthchecker.Watch(&grpc_health_v1.HealthCheckRequest{}, nil) | ||
assert.Error(t, err) | ||
assert.Equal(t, "rpc error: code = Unimplemented desc = not implemented", err.Error()) | ||
} |
Oops, something went wrong.