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

Function TestReadFileWithTemplateUpdate

enterprise/coderd/templates_test.go:1911–1957  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1909}
1910
1911func TestReadFileWithTemplateUpdate(t *testing.T) {
1912 t.Parallel()
1913 t.Run("HasTemplateUpdate", func(t *testing.T) {
1914 t.Parallel()
1915
1916 // Upload a file
1917 client, first := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
1918 Features: license.Features{
1919 codersdk.FeatureTemplateRBAC: 1,
1920 },
1921 }})
1922
1923 ctx := testutil.Context(t, testutil.WaitLong)
1924
1925 //nolint:gocritic // regular user cannot create file
1926 resp, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(make([]byte, 1024)))
1927 require.NoError(t, err)
1928
1929 // Make a new user
1930 member, memberData := coderdtest.CreateAnotherUser(t, client, first.OrganizationID)
1931
1932 // Try to download file, this should fail
1933 _, _, err = member.Download(ctx, resp.ID)
1934 require.Error(t, err, "no template yet")
1935
1936 // Make a new template version with the file
1937 version := coderdtest.CreateTemplateVersion(t, client, first.OrganizationID, nil, func(request *codersdk.CreateTemplateVersionRequest) {
1938 request.FileID = resp.ID
1939 })
1940 template := coderdtest.CreateTemplate(t, client, first.OrganizationID, version.ID)
1941
1942 // Not in acl yet
1943 _, _, err = member.Download(ctx, resp.ID)
1944 require.Error(t, err, "not in acl yet")
1945
1946 //nolint:gocritic // regular user cannot update template acl
1947 err = client.UpdateTemplateACL(ctx, template.ID, codersdk.UpdateTemplateACL{
1948 UserPerms: map[string]codersdk.TemplateRole{
1949 memberData.ID.String(): codersdk.TemplateRoleAdmin,
1950 },
1951 })
1952 require.NoError(t, err)
1953
1954 _, _, err = member.Download(ctx, resp.ID)
1955 require.NoError(t, err)
1956 })
1957}
1958
1959// TestTemplateAccess tests the rego -> sql conversion. We need to implement
1960// this test on at least 1 table type to ensure that the conversion is correct.

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
ContextFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
DownloadMethod · 0.80
UpdateTemplateACLMethod · 0.80
RunMethod · 0.65
UploadMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected