mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
- Refactors `checkProvisioners` into `db2sdk.MatchedProvisioners` - Adds a separate RBAC subject just for reading provisioner daemons - Adds matched provisioners information to additional endpoints relating to workspace builds and templates -Updates existing unit tests for above endpoints -Adds API endpoint for matched provisioners of template dry-run job -Updates CLI to show warning when creating/starting/stopping/deleting workspaces for which no provisoners are available --------- Co-authored-by: Danny Kopping <danny@coder.com>
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package cliutil_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/cli/cliutil"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func TestWarnMatchedProvisioners(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, tt := range []struct {
|
|
name string
|
|
mp *codersdk.MatchedProvisioners
|
|
job codersdk.ProvisionerJob
|
|
expect string
|
|
}{
|
|
{
|
|
name: "no_match",
|
|
mp: &codersdk.MatchedProvisioners{
|
|
Count: 0,
|
|
Available: 0,
|
|
},
|
|
job: codersdk.ProvisionerJob{
|
|
Status: codersdk.ProvisionerJobPending,
|
|
},
|
|
expect: `there are no provisioners that accept the required tags`,
|
|
},
|
|
{
|
|
name: "no_available",
|
|
mp: &codersdk.MatchedProvisioners{
|
|
Count: 1,
|
|
Available: 0,
|
|
},
|
|
job: codersdk.ProvisionerJob{
|
|
Status: codersdk.ProvisionerJobPending,
|
|
},
|
|
expect: `Provisioners that accept the required tags have not responded for longer than expected`,
|
|
},
|
|
{
|
|
name: "match",
|
|
mp: &codersdk.MatchedProvisioners{
|
|
Count: 1,
|
|
Available: 1,
|
|
},
|
|
job: codersdk.ProvisionerJob{
|
|
Status: codersdk.ProvisionerJobPending,
|
|
},
|
|
},
|
|
{
|
|
name: "not_pending",
|
|
mp: &codersdk.MatchedProvisioners{},
|
|
job: codersdk.ProvisionerJob{
|
|
Status: codersdk.ProvisionerJobRunning,
|
|
},
|
|
},
|
|
} {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
var w strings.Builder
|
|
cliutil.WarnMatchedProvisioners(&w, tt.mp, tt.job)
|
|
if tt.expect != "" {
|
|
require.Contains(t, w.String(), tt.expect)
|
|
} else {
|
|
require.Empty(t, w.String())
|
|
}
|
|
})
|
|
}
|
|
}
|