Files
fn-serverless/api/agent/static_pool_test.go
Tolga Ceylan fce1e54746 fn: remove dead code in static pool (#1052)
Static pool is oriented for testing/basic usage and
as it's name implies it is a static pool. Therefore,
removing unnecessary/dead code.
2018-06-08 15:57:06 -07:00

73 lines
1.6 KiB
Go

package agent
import (
"context"
"errors"
"testing"
pool "github.com/fnproject/fn/api/runnerpool"
)
func setupStaticPool(runners []string) pool.RunnerPool {
return NewStaticRunnerPool(runners, nil, "", mockRunnerFactory)
}
var (
ErrorGarbanzoBeans = errors.New("yes, that's right. Garbanzo beans...")
)
type mockStaticRunner struct {
address string
}
func (r *mockStaticRunner) TryExec(ctx context.Context, call pool.RunnerCall) (bool, error) {
return true, nil
}
func (r *mockStaticRunner) Close(context.Context) error {
return ErrorGarbanzoBeans
}
func (r *mockStaticRunner) Address() string {
return r.address
}
func mockRunnerFactory(addr, cn string, pki *pool.PKIData) (pool.Runner, error) {
return &mockStaticRunner{address: addr}, nil
}
func TestNewStaticPool(t *testing.T) {
addrs := []string{"127.0.0.1:8080", "127.0.0.1:8081"}
np := setupStaticPool(addrs)
runners, err := np.Runners(nil)
if err != nil {
t.Fatalf("Failed to list runners %v", err)
}
if len(runners) != len(addrs) {
t.Fatalf("Invalid number of runners %v", len(runners))
}
err = np.Shutdown(context.Background())
if err != ErrorGarbanzoBeans {
t.Fatalf("Expected garbanzo beans error from shutdown %v", err)
}
}
func TestEmptyPool(t *testing.T) {
np := setupStaticPool(nil).(*staticRunnerPool)
runners, err := np.Runners(nil)
if err != nil {
t.Fatalf("Failed to list runners %v", err)
}
if len(runners) != 0 {
t.Fatalf("Invalid number of runners %v", len(runners))
}
err = np.Shutdown(context.Background())
if err != nil {
t.Fatalf("Unexpected error from shutdown %v", err)
}
}