MCPcopy Index your code
hub / github.com/coder/coder / TestGetWorkspaceAgentByID_FastPath

Function TestGetWorkspaceAgentByID_FastPath

coderd/database/dbauthz/dbauthz_test.go:6713–6789  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6711}
6712
6713func TestGetWorkspaceAgentByID_FastPath(t *testing.T) {
6714 t.Parallel()
6715
6716 agentID := uuid.New()
6717 ownerID := uuid.New()
6718 wsID := uuid.New()
6719 orgID := uuid.New()
6720
6721 agent := database.WorkspaceAgent{
6722 ID: agentID,
6723 Name: "test-agent",
6724 }
6725
6726 workspace := database.Workspace{
6727 ID: wsID,
6728 OwnerID: ownerID,
6729 OrganizationID: orgID,
6730 }
6731
6732 wsIdentity := database.WorkspaceIdentity{
6733 ID: wsID,
6734 OwnerID: ownerID,
6735 OrganizationID: orgID,
6736 }
6737
6738 actor := rbac.Subject{
6739 ID: ownerID.String(),
6740 Roles: rbac.RoleIdentifiers{rbac.RoleOwner()},
6741 Groups: []string{orgID.String()},
6742 Scope: rbac.ScopeAll,
6743 }
6744
6745 authorizer := &coderdtest.RecordingAuthorizer{
6746 Wrapped: (&coderdtest.FakeAuthorizer{}).AlwaysReturn(nil),
6747 }
6748
6749 t.Run("WithWorkspaceRBAC", func(t *testing.T) {
6750 t.Parallel()
6751
6752 ctx := dbauthz.As(context.Background(), actor)
6753 ctrl := gomock.NewController(t)
6754 mockDB := dbmock.NewMockStore(ctrl)
6755
6756 rbacObj := wsIdentity.RBACObject()
6757 ctx, err := dbauthz.WithWorkspaceRBAC(ctx, rbacObj)
6758 require.NoError(t, err)
6759
6760 mockDB.EXPECT().Wrappers().Return([]string{})
6761 // GetWorkspaceByAgentID should NOT be called
6762 mockDB.EXPECT().GetWorkspaceAgentByID(gomock.Any(), agentID).Return(agent, nil)
6763
6764 q := dbauthz.New(mockDB, authorizer, slogtest.Make(t, nil), coderdtest.AccessControlStorePointer())
6765
6766 result, err := q.GetWorkspaceAgentByID(ctx, agentID)
6767 require.NoError(t, err)
6768 require.Equal(t, agent, result)
6769 })
6770

Callers

nothing calls this directly

Calls 15

RBACObjectMethod · 0.95
EXPECTMethod · 0.95
RoleOwnerFunction · 0.92
AsFunction · 0.92
NewMockStoreFunction · 0.92
WithWorkspaceRBACFunction · 0.92
NewFunction · 0.92
AlwaysReturnMethod · 0.80
NewMethod · 0.65
RunMethod · 0.65
WrappersMethod · 0.65

Tested by

no test coverage detected