fixup:(bsr): Correctly reference subcontainers when opening

This is a fixup for 60785b5a8
This commit is contained in:
Timothy Messier committed 2023-05-31 12:18:21 +00:00
1 parent 738a6c6472
commit b9de6cf00b
2 files changed
+18 -10

No files matched your search

+14 -5
View File
@@ -718,15 +718,20 @@ func (s *Session) NewConnection(ctx context.Context, meta *ConnectionMeta) (*Con
// OpenConnection will open and validate a BSR connection
func (s *Session) OpenConnection(ctx context.Context, connId string) (*Connection, error) {
const op = "bsr.OpenConnection"
const op = "bsr.(Session).OpenConnection"
switch {
case connId == "":
return nil, fmt.Errorf("%s: missing connection id: %w", op, ErrInvalidParameter)
case !s.Meta.connections[connId]:
}
name := fmt.Sprintf(connectionFile, connId)
switch {
case !s.Meta.connections[name]:
return nil, fmt.Errorf("%s: connection id does not exist within this session: %w", op, ErrInvalidParameter)
}
c, err := s.container.container.SubContainer(ctx, connId)
c, err := s.container.container.SubContainer(ctx, name)
if err != nil {
return nil, err
}
@@ -856,11 +861,15 @@ func (c *Connection) OpenChannel(ctx context.Context, chanId string) (*Channel,
switch {
case chanId == "":
return nil, fmt.Errorf("%s: missing channel id: %w", op, ErrInvalidParameter)
case !c.Meta.channels[chanId]:
}
name := fmt.Sprintf(channelFile, chanId)
switch {
case !c.Meta.channels[name]:
return nil, fmt.Errorf("%s: channel id does not exist within this connection: %w", op, ErrInvalidParameter)
}
con, err := c.container.container.SubContainer(ctx, chanId)
con, err := c.container.container.SubContainer(ctx, name)
if err != nil {
return nil, err
}
+4 -5
View File
@@ -5,7 +5,6 @@ package bsr
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/boundary/internal/bsr/internal/fstest"
@@ -114,13 +113,13 @@ func TestOpenBSRMethods(t *testing.T) {
sesh.Meta.connections = opSesh.Meta.connections
require.Equal(t, sesh.Meta, opSesh.Meta)
opConn, err := opSesh.OpenConnection(ctx, fmt.Sprintf("connection.%s", connectionId))
opConn, err := opSesh.OpenConnection(ctx, connectionId)
require.NoError(t, err)
require.NotNil(t, opConn)
conn.Meta.channels = opConn.Meta.channels
require.Equal(t, conn.Meta, opConn.Meta)
opChan, err := opConn.OpenChannel(ctx, fmt.Sprintf("channel.%s", channelId))
opChan, err := opConn.OpenChannel(ctx, channelId)
require.NoError(t, err)
require.NotNil(t, opChan)
require.Equal(t, ch.Meta, opChan.Meta)
@@ -204,14 +203,14 @@ func TestOpenConnection(t *testing.T) {
{
name: "no-conn-id",
wantErr: true,
wantErrContains: "bsr.OpenConnection: missing connection id: invalid parameter",
wantErrContains: "bsr.(Session).OpenConnection: missing connection id: invalid parameter",
},
{
name: "bad-conn-id",
id: "bogus",
wantErr: true,
wantErrContains: "bsr.OpenConnection: connection id does not exist within this session: invalid parameter",
wantErrContains: "bsr.(Session).OpenConnection: connection id does not exist within this session: invalid parameter",
},
}
for _, tc := range cases {