(t *testing.T)
| 1718 | } |
| 1719 | |
| 1720 | func TestTemplateVersionDryRunLogsFormat(t *testing.T) { |
| 1721 | t.Parallel() |
| 1722 | |
| 1723 | // Setup: Create template version and dry-run job with logs using dbfake. |
| 1724 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 1725 | user := coderdtest.CreateFirstUser(t, client) |
| 1726 | |
| 1727 | tv := dbfake.TemplateVersion(t, db). |
| 1728 | Seed(database.TemplateVersion{ |
| 1729 | OrganizationID: user.OrganizationID, |
| 1730 | CreatedBy: user.UserID, |
| 1731 | }). |
| 1732 | Do() |
| 1733 | |
| 1734 | // Create a dry-run provisioner job. |
| 1735 | dryRunInput, err := json.Marshal(provisionerdserver.TemplateVersionDryRunJob{ |
| 1736 | TemplateVersionID: tv.TemplateVersion.ID, |
| 1737 | }) |
| 1738 | require.NoError(t, err) |
| 1739 | |
| 1740 | dryRunJob := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 1741 | OrganizationID: user.OrganizationID, |
| 1742 | InitiatorID: user.UserID, |
| 1743 | Type: database.ProvisionerJobTypeTemplateVersionDryRun, |
| 1744 | Input: dryRunInput, |
| 1745 | }) |
| 1746 | |
| 1747 | // Insert test log directly into database. |
| 1748 | jl := dbgen.ProvisionerJobLog(t, db, database.ProvisionerJobLog{ |
| 1749 | JobID: dryRunJob.ID, |
| 1750 | Stage: "Planning", |
| 1751 | Source: database.LogSourceProvisioner, |
| 1752 | Level: database.LogLevelInfo, |
| 1753 | Output: "test dry-run log output", |
| 1754 | }) |
| 1755 | |
| 1756 | tests := []struct { |
| 1757 | name string |
| 1758 | queryParams string |
| 1759 | expectedStatus int |
| 1760 | expectedContentType string |
| 1761 | checkBody func(t *testing.T, body string) |
| 1762 | }{ |
| 1763 | { |
| 1764 | name: "JSON", |
| 1765 | queryParams: "", |
| 1766 | expectedStatus: http.StatusOK, |
| 1767 | expectedContentType: "application/json", |
| 1768 | checkBody: func(t *testing.T, body string) { |
| 1769 | assert.NotEmpty(t, body) |
| 1770 | }, |
| 1771 | }, |
| 1772 | { |
| 1773 | name: "Text", |
| 1774 | queryParams: "?format=text", |
| 1775 | expectedStatus: http.StatusOK, |
| 1776 | expectedContentType: "text/plain", |
| 1777 | checkBody: func(t *testing.T, body string) { |
nothing calls this directly
no test coverage detected