mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
2c8b264d78
Closes https://github.com/coder/coder/issues/14704 --------- Co-authored-by: Kayla Washburn-Love <mckayla@hey.com>
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/cli/clitest"
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
|
|
"github.com/coder/coder/v2/enterprise/coderd/license"
|
|
"github.com/coder/coder/v2/testutil"
|
|
)
|
|
|
|
func TestEnterpriseListTemplates(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("MultiOrg", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
client, owner := coderdenttest.New(t, &coderdenttest.Options{
|
|
Options: &coderdtest.Options{
|
|
IncludeProvisionerDaemon: true,
|
|
},
|
|
LicenseOptions: &coderdenttest.LicenseOptions{
|
|
Features: license.Features{
|
|
codersdk.FeatureMultipleOrganizations: 1,
|
|
codersdk.FeatureExternalProvisionerDaemons: 1,
|
|
},
|
|
},
|
|
})
|
|
|
|
// Template in the first organization
|
|
firstVersion := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
|
|
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, firstVersion.ID)
|
|
_ = coderdtest.CreateTemplate(t, client, owner.OrganizationID, firstVersion.ID)
|
|
|
|
secondOrg := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{
|
|
IncludeProvisionerDaemon: true,
|
|
})
|
|
secondVersion := coderdtest.CreateTemplateVersion(t, client, secondOrg.ID, nil)
|
|
_ = coderdtest.CreateTemplate(t, client, secondOrg.ID, secondVersion.ID)
|
|
|
|
// Create a site wide template admin
|
|
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
|
|
|
|
inv, root := clitest.New(t, "templates", "list", "--output=json")
|
|
clitest.SetupConfig(t, templateAdmin, root)
|
|
|
|
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
|
|
defer cancelFunc()
|
|
|
|
out := bytes.NewBuffer(nil)
|
|
inv.Stdout = out
|
|
err := inv.WithContext(ctx).Run()
|
|
require.NoError(t, err)
|
|
|
|
var templates []codersdk.Template
|
|
require.NoError(t, json.Unmarshal(out.Bytes(), &templates))
|
|
require.Len(t, templates, 2)
|
|
})
|
|
}
|