|
| 1 | +package dtrack |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestProjectPropertyService_GetAll(t *testing.T) { |
| 11 | + client := setUpContainer(t, testContainerOptions{ |
| 12 | + APIPermissions: []string{ |
| 13 | + PermissionPortfolioManagement, |
| 14 | + }, |
| 15 | + }) |
| 16 | + |
| 17 | + project, err := client.Project.Create(context.Background(), Project{ |
| 18 | + Name: "acme-app", |
| 19 | + Version: "1.0.0", |
| 20 | + }) |
| 21 | + require.NoError(t, err) |
| 22 | + |
| 23 | + po := PageOptions{PageSize: 10} |
| 24 | + |
| 25 | + // Baseline: no properties yet |
| 26 | + properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po) |
| 27 | + require.NoError(t, err) |
| 28 | + // The api does not return TotalCount as it seems not to be paginated (although we can supply page options) |
| 29 | + //require.Equal(t, 0, properties.TotalCount) |
| 30 | + require.Empty(t, properties.Items) |
| 31 | + |
| 32 | + // Create a property |
| 33 | + _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ |
| 34 | + Group: "test-group", |
| 35 | + Name: "test-property", |
| 36 | + Value: "test-value", |
| 37 | + Type: "STRING", |
| 38 | + }) |
| 39 | + require.NoError(t, err) |
| 40 | + |
| 41 | + // Verify it appears in GetAll |
| 42 | + properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po) |
| 43 | + require.NoError(t, err) |
| 44 | + // The api does not return TotalCount as it seems not to be paginated (although we can supply page options) |
| 45 | + //require.Equal(t, 1, properties.TotalCount) |
| 46 | + require.Len(t, properties.Items, 1) |
| 47 | + require.Equal(t, "test-group", properties.Items[0].Group) |
| 48 | + require.Equal(t, "test-property", properties.Items[0].Name) |
| 49 | + require.Equal(t, "test-value", properties.Items[0].Value) |
| 50 | + require.Equal(t, "STRING", properties.Items[0].Type) |
| 51 | +} |
| 52 | + |
| 53 | +func TestProjectPropertyService_Create(t *testing.T) { |
| 54 | + client := setUpContainer(t, testContainerOptions{ |
| 55 | + APIPermissions: []string{ |
| 56 | + PermissionPortfolioManagement, |
| 57 | + }, |
| 58 | + }) |
| 59 | + |
| 60 | + project, err := client.Project.Create(context.Background(), Project{ |
| 61 | + Name: "acme-app", |
| 62 | + Version: "1.0.0", |
| 63 | + }) |
| 64 | + require.NoError(t, err) |
| 65 | + |
| 66 | + property, err := client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ |
| 67 | + Group: "test-group", |
| 68 | + Name: "test-property", |
| 69 | + Value: "test-value", |
| 70 | + Type: "STRING", |
| 71 | + Description: "a test property", |
| 72 | + }) |
| 73 | + require.NoError(t, err) |
| 74 | + require.Equal(t, "test-group", property.Group) |
| 75 | + require.Equal(t, "test-property", property.Name) |
| 76 | + require.Equal(t, "test-value", property.Value) |
| 77 | + require.Equal(t, "STRING", property.Type) |
| 78 | + require.Equal(t, "a test property", property.Description) |
| 79 | +} |
| 80 | + |
| 81 | +func TestProjectPropertyService_Update(t *testing.T) { |
| 82 | + client := setUpContainer(t, testContainerOptions{ |
| 83 | + APIPermissions: []string{ |
| 84 | + PermissionPortfolioManagement, |
| 85 | + }, |
| 86 | + }) |
| 87 | + |
| 88 | + project, err := client.Project.Create(context.Background(), Project{ |
| 89 | + Name: "acme-app", |
| 90 | + Version: "1.0.0", |
| 91 | + }) |
| 92 | + require.NoError(t, err) |
| 93 | + |
| 94 | + // Create a property first |
| 95 | + _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ |
| 96 | + Group: "test-group", |
| 97 | + Name: "test-property", |
| 98 | + Value: "original-value", |
| 99 | + Type: "STRING", |
| 100 | + }) |
| 101 | + require.NoError(t, err) |
| 102 | + |
| 103 | + // Update the property |
| 104 | + updated, err := client.ProjectProperty.Update(context.Background(), project.UUID, ProjectProperty{ |
| 105 | + Group: "test-group", |
| 106 | + Name: "test-property", |
| 107 | + Value: "updated-value", |
| 108 | + Type: "STRING", |
| 109 | + }) |
| 110 | + require.NoError(t, err) |
| 111 | + require.Equal(t, "test-group", updated.Group) |
| 112 | + require.Equal(t, "test-property", updated.Name) |
| 113 | + require.Equal(t, "updated-value", updated.Value) |
| 114 | + require.Equal(t, "STRING", updated.Type) |
| 115 | +} |
| 116 | + |
| 117 | +func TestProjectPropertyService_Delete(t *testing.T) { |
| 118 | + client := setUpContainer(t, testContainerOptions{ |
| 119 | + APIPermissions: []string{ |
| 120 | + PermissionPortfolioManagement, |
| 121 | + }, |
| 122 | + }) |
| 123 | + |
| 124 | + po := PageOptions{PageSize: 10} |
| 125 | + |
| 126 | + project, err := client.Project.Create(context.Background(), Project{ |
| 127 | + Name: "acme-app", |
| 128 | + Version: "1.0.0", |
| 129 | + }) |
| 130 | + require.NoError(t, err) |
| 131 | + |
| 132 | + // Create a property |
| 133 | + _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ |
| 134 | + Group: "test-group", |
| 135 | + Name: "test-property", |
| 136 | + Value: "test-value", |
| 137 | + Type: "STRING", |
| 138 | + }) |
| 139 | + require.NoError(t, err) |
| 140 | + |
| 141 | + // Verify presence |
| 142 | + properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po) |
| 143 | + require.NoError(t, err) |
| 144 | + require.Len(t, properties.Items, 1) |
| 145 | + |
| 146 | + // Delete the property |
| 147 | + err = client.ProjectProperty.Delete(context.Background(), project.UUID, "test-group", "test-property") |
| 148 | + require.NoError(t, err) |
| 149 | + |
| 150 | + // Verify absence |
| 151 | + properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po) |
| 152 | + require.NoError(t, err) |
| 153 | + require.Len(t, properties.Items, 0) |
| 154 | + |
| 155 | +} |
0 commit comments