mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
They're currently randomly in a bunch of different files. This cleans up the handler functions to be in the file of the type they return.
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package coderd_test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd/coderdtest"
|
|
"github.com/coder/coder/coderd/database"
|
|
"github.com/coder/coder/codersdk"
|
|
"github.com/coder/coder/provisionersdk"
|
|
)
|
|
|
|
func TestProvisionerDaemons(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("PayloadTooBig", func(t *testing.T) {
|
|
t.Parallel()
|
|
if runtime.GOOS == "windows" {
|
|
// Takes too long to allocate memory on Windows!
|
|
t.Skip()
|
|
}
|
|
client := coderdtest.New(t, nil)
|
|
user := coderdtest.CreateFirstUser(t, client)
|
|
coderdtest.NewProvisionerDaemon(t, client)
|
|
data := make([]byte, provisionersdk.MaxMessageSize)
|
|
rand.Read(data)
|
|
resp, err := client.Upload(context.Background(), codersdk.ContentTypeTar, data)
|
|
require.NoError(t, err)
|
|
t.Log(resp.Hash)
|
|
|
|
version, err := client.CreateTemplateVersion(context.Background(), user.OrganizationID, codersdk.CreateTemplateVersionRequest{
|
|
StorageMethod: database.ProvisionerStorageMethodFile,
|
|
StorageSource: resp.Hash,
|
|
Provisioner: database.ProvisionerTypeEcho,
|
|
})
|
|
require.NoError(t, err)
|
|
require.Eventually(t, func() bool {
|
|
var err error
|
|
version, err = client.TemplateVersion(context.Background(), version.ID)
|
|
require.NoError(t, err)
|
|
return version.Job.Error != ""
|
|
}, 5*time.Second, 25*time.Millisecond)
|
|
})
|
|
}
|
|
|
|
func TestProvisionerDaemonsByOrganization(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("NoAuth", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t, nil)
|
|
_, err := client.ProvisionerDaemonsByOrganization(context.Background(), uuid.New())
|
|
require.Error(t, err)
|
|
})
|
|
|
|
t.Run("Get", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t, nil)
|
|
user := coderdtest.CreateFirstUser(t, client)
|
|
_, err := client.ProvisionerDaemonsByOrganization(context.Background(), user.OrganizationID)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|