Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Improve coverage by uploading PostgreSQL tests #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ jobs:
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: go run scripts/datadog-cireport/main.go gotests.xml

- uses: codecov/codecov-action@v2
if: github.actor != 'dependabot[bot]'
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-${{ matrix.os }}
fail_ci_if_error: true

deploy:
name: "deploy"
runs-on: ubuntu-latest
Expand Down
44 changes: 44 additions & 0 deletions cli/workspacecreate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cli_test

import (
"testing"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/pty/ptytest"
"github.com/stretchr/testify/require"
)

func TestWorkspaceCreate(t *testing.T) {
t.Parallel()
t.Run("Create", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
cmd, root := clitest.New(t, "workspaces", "create", "my-workspace", "--project", project.Name)
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
}()
matches := []string{
"Create workspace", "yes",
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)
pty.WriteLine(value)
}
<-doneChan
})
}
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ignore:
- database/databasefake
# These are generated or don't require tests.
- cmd
- coderd/tunnel
- database/dump
- database/postgres
- peerbroker/proto
Expand Down
92 changes: 67 additions & 25 deletions coderd/projectversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,76 @@ func TestProjectVersion(t *testing.T) {

func TestPatchCancelProjectVersion(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Log{
Log: &proto.Log{},
},
}},
t.Run("AlreadyCompleted", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
err := client.CancelProjectVersion(context.Background(), version.ID)
var apiErr *codersdk.Error
require.ErrorAs(t, err, &apiErr)
require.Equal(t, http.StatusPreconditionFailed, apiErr.StatusCode())
})
require.Eventually(t, func() bool {
var err error
version, err = client.ProjectVersion(context.Background(), version.ID)
t.Run("AlreadyCanceled", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Log{
Log: &proto.Log{},
},
}},
})
require.Eventually(t, func() bool {
var err error
version, err = client.ProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
t.Logf("Status: %s", version.Job.Status)
return version.Job.Status == codersdk.ProvisionerJobRunning
}, 5*time.Second, 25*time.Millisecond)
err := client.CancelProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
t.Logf("Status: %s", version.Job.Status)
return version.Job.Status == codersdk.ProvisionerJobRunning
}, 5*time.Second, 25*time.Millisecond)
err := client.CancelProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
require.Eventually(t, func() bool {
var err error
version, err = client.ProjectVersion(context.Background(), version.ID)
err = client.CancelProjectVersion(context.Background(), version.ID)
var apiErr *codersdk.Error
require.ErrorAs(t, err, &apiErr)
require.Equal(t, http.StatusPreconditionFailed, apiErr.StatusCode())
})
t.Run("Success", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
coderdtest.NewProvisionerDaemon(t, client)
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Log{
Log: &proto.Log{},
},
}},
})
require.Eventually(t, func() bool {
var err error
version, err = client.ProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
t.Logf("Status: %s", version.Job.Status)
return version.Job.Status == codersdk.ProvisionerJobRunning
}, 5*time.Second, 25*time.Millisecond)
err := client.CancelProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
// The echo provisioner doesn't respond to a shutdown request,
// so the job cancel will time out and fail.
return version.Job.Status == codersdk.ProvisionerJobFailed
}, 5*time.Second, 25*time.Millisecond)
require.Eventually(t, func() bool {
var err error
version, err = client.ProjectVersion(context.Background(), version.ID)
require.NoError(t, err)
// The echo provisioner doesn't respond to a shutdown request,
// so the job cancel will time out and fail.
return version.Job.Status == codersdk.ProvisionerJobFailed
}, 5*time.Second, 25*time.Millisecond)
})
}

func TestProjectVersionSchema(t *testing.T) {
Expand Down