MCPcopy Index your code
hub / github.com/coder/coder / TestInsertWorkspaceAgentLogs

Function TestInsertWorkspaceAgentLogs

coderd/database/querier_test.go:1772–1816  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1770}
1771
1772func TestInsertWorkspaceAgentLogs(t *testing.T) {
1773 t.Parallel()
1774 if testing.Short() {
1775 t.SkipNow()
1776 }
1777 sqlDB := testSQLDB(t)
1778 ctx := context.Background()
1779 err := migrations.Up(sqlDB)
1780 require.NoError(t, err)
1781 db := database.New(sqlDB)
1782 org := dbgen.Organization(t, db, database.Organization{})
1783 job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
1784 OrganizationID: org.ID,
1785 })
1786 resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{
1787 JobID: job.ID,
1788 })
1789 agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{
1790 ResourceID: resource.ID,
1791 })
1792 source := dbgen.WorkspaceAgentLogSource(t, db, database.WorkspaceAgentLogSource{
1793 WorkspaceAgentID: agent.ID,
1794 })
1795 logs, err := db.InsertWorkspaceAgentLogs(ctx, database.InsertWorkspaceAgentLogsParams{
1796 AgentID: agent.ID,
1797 CreatedAt: dbtime.Now(),
1798 Output: []string{"first"},
1799 Level: []database.LogLevel{database.LogLevelInfo},
1800 LogSourceID: source.ID,
1801 // 1 MB is the max
1802 OutputLength: 1 << 20,
1803 })
1804 require.NoError(t, err)
1805 require.Equal(t, int64(1), logs[0].ID)
1806
1807 _, err = db.InsertWorkspaceAgentLogs(ctx, database.InsertWorkspaceAgentLogsParams{
1808 AgentID: agent.ID,
1809 CreatedAt: dbtime.Now(),
1810 Output: []string{"second"},
1811 Level: []database.LogLevel{database.LogLevelInfo},
1812 LogSourceID: source.ID,
1813 OutputLength: 1,
1814 })
1815 require.True(t, database.IsWorkspaceAgentLogsLimitError(err))
1816}
1817
1818func TestProxyByHostname(t *testing.T) {
1819 t.Parallel()

Callers

nothing calls this directly

Calls 13

UpFunction · 0.92
NewFunction · 0.92
OrganizationFunction · 0.92
ProvisionerJobFunction · 0.92
WorkspaceResourceFunction · 0.92
WorkspaceAgentFunction · 0.92
WorkspaceAgentLogSourceFunction · 0.92
NowFunction · 0.92
SkipNowMethod · 0.80
testSQLDBFunction · 0.70

Tested by

no test coverage detected