mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-24 16:17:11 +08:00
* Convert DeleteProxy RPC from HTTP to gRPC * Use `t.Context()` * Add more greppable TODO * Fix usage of deprecated rpc * Upsert RPC * Use wrapper message for UpsertResponse * gofmt * Simplify godoc * Update response message * Update method names on public api client * fix tests * Introduce UpsertProxyWithoutServer * Edoardo comments * separate * Change to UpsertProxyServer RPC handler
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
// Teleport
|
|
// Copyright (C) 2025 Gravitational, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package cache
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gravitational/teleport/api/types"
|
|
"github.com/gravitational/teleport/api/utils/clientutils"
|
|
"github.com/gravitational/teleport/lib/itertools/stream"
|
|
)
|
|
|
|
// TestProxies tests proxies cache
|
|
func TestProxies(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
p := newTestPack(t, ForProxy)
|
|
t.Cleanup(p.Close)
|
|
|
|
testResources(t, p, testFuncs[types.Server]{
|
|
newResource: func(name string) (types.Server, error) {
|
|
return &types.ServerV2{
|
|
Kind: types.KindProxy,
|
|
Version: types.V2,
|
|
Metadata: types.Metadata{
|
|
Name: name,
|
|
},
|
|
Spec: types.ServerSpecV2{
|
|
Addr: "127.0.0.1:2022",
|
|
},
|
|
}, nil
|
|
},
|
|
create: func(ctx context.Context, s types.Server) error {
|
|
_, err := p.presenceS.UpsertProxyServer(ctx, s)
|
|
return err
|
|
},
|
|
list: p.presenceS.ListProxyServers,
|
|
cacheList: p.cache.ListProxyServers,
|
|
update: func(ctx context.Context, s types.Server) error {
|
|
_, err := p.presenceS.UpsertProxyServer(ctx, s)
|
|
return err
|
|
},
|
|
deleteAll: func(ctx context.Context) error {
|
|
proxies, err := stream.Collect(clientutils.Resources(ctx, p.presenceS.ListProxyServers))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, proxy := range proxies {
|
|
if err := p.presenceS.DeleteProxyServer(ctx, proxy.GetName()); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
}
|