mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
* chore: Rename ProjectHistory to ProjectVersion Version more accurately represents version storage. This forks from the WorkspaceHistory name, but I think it's easier to understand Workspace history. * Rename files * Standardize tests a bit more * Remove Server struct from coderdtest * Improve test coverage for workspace history * Fix linting errors * Fix coderd test leak * Fix coderd test leak * Improve workspace history logs * Standardize test structure for codersdk * Fix linting errors * Fix WebSocket compression * Update coderd/workspaces.go Co-authored-by: Bryan <bryan@coder.com> * Add test for listing project parameters * Cache npm dependencies with setup node * Remove windows npm cache key Co-authored-by: Bryan <bryan@coder.com>
148 lines
4.5 KiB
Go
148 lines
4.5 KiB
Go
package coderd_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd"
|
|
"github.com/coder/coder/coderd/coderdtest"
|
|
"github.com/coder/coder/codersdk"
|
|
"github.com/coder/coder/database"
|
|
)
|
|
|
|
func TestProjects(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("ListEmpty", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
_ = coderdtest.CreateInitialUser(t, client)
|
|
projects, err := client.Projects(context.Background(), "")
|
|
require.NoError(t, err)
|
|
require.NotNil(t, projects)
|
|
require.Len(t, projects, 0)
|
|
})
|
|
|
|
t.Run("List", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
_ = coderdtest.CreateProject(t, client, user.Organization)
|
|
projects, err := client.Projects(context.Background(), "")
|
|
require.NoError(t, err)
|
|
require.Len(t, projects, 1)
|
|
})
|
|
}
|
|
|
|
func TestProjectsByOrganization(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("ListEmpty", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
projects, err := client.Projects(context.Background(), user.Organization)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, projects)
|
|
require.Len(t, projects, 0)
|
|
})
|
|
|
|
t.Run("List", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
_ = coderdtest.CreateProject(t, client, user.Organization)
|
|
projects, err := client.Projects(context.Background(), "")
|
|
require.NoError(t, err)
|
|
require.Len(t, projects, 1)
|
|
})
|
|
}
|
|
|
|
func TestPostProjectsByOrganization(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Create", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
_ = coderdtest.CreateProject(t, client, user.Organization)
|
|
})
|
|
|
|
t.Run("AlreadyExists", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
project := coderdtest.CreateProject(t, client, user.Organization)
|
|
_, err := client.CreateProject(context.Background(), user.Organization, coderd.CreateProjectRequest{
|
|
Name: project.Name,
|
|
Provisioner: database.ProvisionerTypeEcho,
|
|
})
|
|
var apiErr *codersdk.Error
|
|
require.ErrorAs(t, err, &apiErr)
|
|
require.Equal(t, http.StatusConflict, apiErr.StatusCode())
|
|
})
|
|
}
|
|
|
|
func TestProjectByOrganization(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Get", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
project := coderdtest.CreateProject(t, client, user.Organization)
|
|
_, err := client.Project(context.Background(), user.Organization, project.Name)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestPostParametersByProject(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Create", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
project := coderdtest.CreateProject(t, client, user.Organization)
|
|
_, err := client.CreateProjectParameter(context.Background(), user.Organization, project.Name, coderd.CreateParameterValueRequest{
|
|
Name: "somename",
|
|
SourceValue: "tomato",
|
|
SourceScheme: database.ParameterSourceSchemeData,
|
|
DestinationScheme: database.ParameterDestinationSchemeEnvironmentVariable,
|
|
DestinationValue: "moo",
|
|
})
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestParametersByProject(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("ListEmpty", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
project := coderdtest.CreateProject(t, client, user.Organization)
|
|
params, err := client.ProjectParameters(context.Background(), user.Organization, project.Name)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, params)
|
|
})
|
|
|
|
t.Run("List", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t)
|
|
user := coderdtest.CreateInitialUser(t, client)
|
|
project := coderdtest.CreateProject(t, client, user.Organization)
|
|
_, err := client.CreateProjectParameter(context.Background(), user.Organization, project.Name, coderd.CreateParameterValueRequest{
|
|
Name: "example",
|
|
SourceValue: "source-value",
|
|
SourceScheme: database.ParameterSourceSchemeData,
|
|
DestinationScheme: database.ParameterDestinationSchemeEnvironmentVariable,
|
|
DestinationValue: "destination-value",
|
|
})
|
|
require.NoError(t, err)
|
|
params, err := client.ProjectParameters(context.Background(), user.Organization, project.Name)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, params)
|
|
require.Len(t, params, 1)
|
|
})
|
|
}
|