(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func TestTemplatePush(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | |
| 36 | t.Run("OK", func(t *testing.T) { |
| 37 | t.Parallel() |
| 38 | client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) |
| 39 | owner := coderdtest.CreateFirstUser(t, client) |
| 40 | templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 41 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 42 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 43 | |
| 44 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
| 45 | |
| 46 | // Test the cli command. |
| 47 | source := clitest.CreateTemplateVersionSource(t, &echo.Responses{ |
| 48 | Parse: echo.ParseComplete, |
| 49 | ProvisionApply: echo.ApplyComplete, |
| 50 | }) |
| 51 | inv, root := clitest.New(t, "templates", "push", template.Name, "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--name", "example") |
| 52 | clitest.SetupConfig(t, templateAdmin, root) |
| 53 | pty := ptytest.New(t).Attach(inv) |
| 54 | |
| 55 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 56 | inv = inv.WithContext(ctx) |
| 57 | w := clitest.StartWithWaiter(t, inv) |
| 58 | |
| 59 | matches := []struct { |
| 60 | match string |
| 61 | write string |
| 62 | }{ |
| 63 | {match: "Upload", write: "yes"}, |
| 64 | } |
| 65 | for _, m := range matches { |
| 66 | pty.ExpectMatchContext(ctx, m.match) |
| 67 | pty.WriteLine(m.write) |
| 68 | } |
| 69 | |
| 70 | w.RequireSuccess() |
| 71 | |
| 72 | // Assert that the template version changed. |
| 73 | templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{ |
| 74 | TemplateID: template.ID, |
| 75 | }) |
| 76 | require.NoError(t, err) |
| 77 | assert.Len(t, templateVersions, 2) |
| 78 | assert.NotEqual(t, template.ActiveVersionID, templateVersions[1].ID) |
| 79 | require.Equal(t, "example", templateVersions[1].Name) |
| 80 | }) |
| 81 | |
| 82 | t.Run("Message less than or equal to 72 chars", func(t *testing.T) { |
| 83 | t.Parallel() |
| 84 | client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) |
| 85 | owner := coderdtest.CreateFirstUser(t, client) |
| 86 | templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 87 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 88 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 89 | |
| 90 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
nothing calls this directly
no test coverage detected