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

Function TestTemplatePull_ActiveOldStdout

cli/templatepull_test.go:114–150  ·  view source on GitHub ↗

Stdout tests that 'templates pull' pulls down the non-latest active template and writes it to stdout.

(t *testing.T)

Source from the content-addressed store, hash-verified

112// Stdout tests that 'templates pull' pulls down the non-latest active template
113// and writes it to stdout.
114func TestTemplatePull_ActiveOldStdout(t *testing.T) {
115 t.Parallel()
116
117 client := coderdtest.New(t, &coderdtest.Options{
118 IncludeProvisionerDaemon: true,
119 })
120 owner := coderdtest.CreateFirstUser(t, client)
121 templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
122
123 source1 := genTemplateVersionSource()
124 source2 := genTemplateVersionSource()
125
126 expected, err := echo.Tar(source1)
127 require.NoError(t, err)
128
129 version1 := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, source1)
130 _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version1.ID)
131
132 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version1.ID)
133
134 updatedVersion := coderdtest.UpdateTemplateVersion(t, client, owner.OrganizationID, source2, template.ID)
135 _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, updatedVersion.ID)
136
137 inv, root := clitest.New(t, "templates", "pull", "--tar", template.Name)
138 clitest.SetupConfig(t, templateAdmin, root)
139
140 var buf bytes.Buffer
141 inv.Stdout = &buf
142 var stderr strings.Builder
143 inv.Stderr = &stderr
144
145 err = inv.Run()
146 require.NoError(t, err)
147
148 require.True(t, bytes.Equal(expected, buf.Bytes()), "tar files differ")
149 require.Contains(t, stderr.String(), "A newer template version than the active version exists.")
150}
151
152// Stdout tests that 'templates pull' pulls down the specified template and
153// writes it to stdout.

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
TarFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
UpdateTemplateVersionFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
genTemplateVersionSourceFunction · 0.85

Tested by

no test coverage detected