(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestProjectVariables(t *testing.T) { |
| 13 | fix := testadmin.New(t) |
| 14 | |
| 15 | t.Run("Set, get and unset variables as a user", func(t *testing.T) { |
| 16 | u1, c1 := fix.NewUser(t) |
| 17 | |
| 18 | r1, err := c1.CreateOrganization(t.Context(), &adminv1.CreateOrganizationRequest{Name: randomName()}) |
| 19 | require.NoError(t, err) |
| 20 | r2, err := c1.CreateProject(t.Context(), &adminv1.CreateProjectRequest{ |
| 21 | Org: r1.Organization.Name, |
| 22 | Project: "proj1", |
| 23 | ProdSlots: 1, |
| 24 | SkipDeploy: true, |
| 25 | }) |
| 26 | require.NoError(t, err) |
| 27 | |
| 28 | // Set a shared variable, a prod-only variable, and a dev-only variable. |
| 29 | _, err = c1.UpdateProjectVariables(t.Context(), &adminv1.UpdateProjectVariablesRequest{ |
| 30 | Org: r1.Organization.Name, |
| 31 | Project: r2.Project.Name, |
| 32 | Variables: map[string]string{"FOO": "shared"}, |
| 33 | }) |
| 34 | require.NoError(t, err) |
| 35 | _, err = c1.UpdateProjectVariables(t.Context(), &adminv1.UpdateProjectVariablesRequest{ |
| 36 | Org: r1.Organization.Name, |
| 37 | Project: r2.Project.Name, |
| 38 | Environment: "prod", |
| 39 | Variables: map[string]string{"BAR": "prod-value"}, |
| 40 | }) |
| 41 | require.NoError(t, err) |
| 42 | _, err = c1.UpdateProjectVariables(t.Context(), &adminv1.UpdateProjectVariablesRequest{ |
| 43 | Org: r1.Organization.Name, |
| 44 | Project: r2.Project.Name, |
| 45 | Environment: "dev", |
| 46 | Variables: map[string]string{"BAZ": "dev-value"}, |
| 47 | }) |
| 48 | require.NoError(t, err) |
| 49 | |
| 50 | // Get shared variables only. |
| 51 | r3, err := c1.GetProjectVariables(t.Context(), &adminv1.GetProjectVariablesRequest{ |
| 52 | Org: r1.Organization.Name, |
| 53 | Project: r2.Project.Name, |
| 54 | }) |
| 55 | require.NoError(t, err) |
| 56 | require.Len(t, r3.Variables, 1) |
| 57 | require.Equal(t, "FOO", r3.Variables[0].Name) |
| 58 | require.Equal(t, "shared", r3.Variables[0].Value) |
| 59 | require.Equal(t, "", r3.Variables[0].Environment) |
| 60 | require.Equal(t, u1.ID, r3.Variables[0].UpdatedByUserId) |
| 61 | |
| 62 | // Get shared and prod variables. |
| 63 | r4, err := c1.GetProjectVariables(t.Context(), &adminv1.GetProjectVariablesRequest{ |
| 64 | Org: r1.Organization.Name, |
| 65 | Project: r2.Project.Name, |
| 66 | Environment: "prod", |
| 67 | }) |
| 68 | require.NoError(t, err) |
| 69 | require.Len(t, r4.Variables, 2) |
nothing calls this directly
no test coverage detected