talos/pkg/grpc/proxy/backend/local_test.go
Andrey Smirnov a068acfbe4 feat: split routerd from apid
New service `routerd` performs exactly single task: based on incoming
API call service name, it routes the requests to the appropriate Talos
service (`networkd`, `osd`, etc.) Service `routerd` listens of file
socket and routes requests to file sockets.

Service `apid` now does single task as well:

* it either fans out request to other `apid` services running on other
nodes and aggregates responses
* or it forwards requests to local `routerd` (when request destination
is local node)

Cons:

* one more proxying layer on request path

Pros:

* more clear service roles
* `routerd` is part of core Talos, services should register with it to
expose their API; no auth in the service (not exposed to the world)
* `apid` might be replaced with other implementation, it depends on TLS infra,
auth, etc.
* `apid` is better segregated from other Talos services (can only access
`routerd`, can't talk to other Talos services directly, so less exposure
in case of a bug)

This change is no-op to the end users.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-03-05 22:05:56 +03:00

46 lines
1.2 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package backend_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
"github.com/talos-systems/grpc-proxy/proxy"
"github.com/talos-systems/talos/pkg/grpc/proxy/backend"
)
func TestLocalInterfaces(t *testing.T) {
assert.Implements(t, (*proxy.Backend)(nil), new(backend.Local))
}
func TestLocalGetConnection(t *testing.T) {
l := backend.NewLocal("test", "/tmp/test.sock")
md := metadata.New(nil)
md.Set("key", "value1", "value2")
ctx := metadata.NewIncomingContext(context.Background(), md)
outCtx1, conn1, err1 := l.GetConnection(ctx)
assert.NoError(t, err1)
assert.NotNil(t, conn1)
mdOut1, ok1 := metadata.FromOutgoingContext(outCtx1)
assert.True(t, ok1)
assert.Equal(t, []string{"value1", "value2"}, mdOut1.Get("key"))
outCtx2, conn2, err2 := l.GetConnection(ctx)
assert.NoError(t, err2)
assert.Equal(t, conn1, conn2) // connection is cached
mdOut2, ok2 := metadata.FromOutgoingContext(outCtx2)
assert.True(t, ok2)
assert.Equal(t, []string{"value1", "value2"}, mdOut2.Get("key"))
}