forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Fix: deletion of ProjectProperties #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nscuro
merged 2 commits into
DependencyTrack:main
from
BastiaanN:fix-project-property-delete
Apr 14, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| package dtrack | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestProjectPropertyService_GetAll(t *testing.T) { | ||
| client := setUpContainer(t, testContainerOptions{ | ||
| APIPermissions: []string{ | ||
| PermissionPortfolioManagement, | ||
| }, | ||
| }) | ||
|
|
||
| project, err := client.Project.Create(context.Background(), Project{ | ||
| Name: "acme-app", | ||
| Version: "1.0.0", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| po := PageOptions{PageSize: 10} | ||
|
|
||
| // Baseline: no properties yet | ||
| properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po) | ||
| require.NoError(t, err) | ||
| // The api does not return TotalCount as it seems not to be paginated (although we can supply page options) | ||
| //require.Equal(t, 0, properties.TotalCount) | ||
| require.Empty(t, properties.Items) | ||
|
|
||
| // Create a property | ||
| _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ | ||
| Group: "test-group", | ||
| Name: "test-property", | ||
| Value: "test-value", | ||
| Type: "STRING", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify it appears in GetAll | ||
| properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po) | ||
| require.NoError(t, err) | ||
| // The api does not return TotalCount as it seems not to be paginated (although we can supply page options) | ||
| //require.Equal(t, 1, properties.TotalCount) | ||
| require.Len(t, properties.Items, 1) | ||
| require.Equal(t, "test-group", properties.Items[0].Group) | ||
| require.Equal(t, "test-property", properties.Items[0].Name) | ||
| require.Equal(t, "test-value", properties.Items[0].Value) | ||
| require.Equal(t, "STRING", properties.Items[0].Type) | ||
| } | ||
|
|
||
| func TestProjectPropertyService_Create(t *testing.T) { | ||
| client := setUpContainer(t, testContainerOptions{ | ||
| APIPermissions: []string{ | ||
| PermissionPortfolioManagement, | ||
| }, | ||
| }) | ||
|
|
||
| project, err := client.Project.Create(context.Background(), Project{ | ||
| Name: "acme-app", | ||
| Version: "1.0.0", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| property, err := client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ | ||
| Group: "test-group", | ||
| Name: "test-property", | ||
| Value: "test-value", | ||
| Type: "STRING", | ||
| Description: "a test property", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "test-group", property.Group) | ||
| require.Equal(t, "test-property", property.Name) | ||
| require.Equal(t, "test-value", property.Value) | ||
| require.Equal(t, "STRING", property.Type) | ||
| require.Equal(t, "a test property", property.Description) | ||
| } | ||
|
|
||
| func TestProjectPropertyService_Update(t *testing.T) { | ||
| client := setUpContainer(t, testContainerOptions{ | ||
| APIPermissions: []string{ | ||
| PermissionPortfolioManagement, | ||
| }, | ||
| }) | ||
|
|
||
| project, err := client.Project.Create(context.Background(), Project{ | ||
| Name: "acme-app", | ||
| Version: "1.0.0", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Create a property first | ||
| _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ | ||
| Group: "test-group", | ||
| Name: "test-property", | ||
| Value: "original-value", | ||
| Type: "STRING", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Update the property | ||
| updated, err := client.ProjectProperty.Update(context.Background(), project.UUID, ProjectProperty{ | ||
| Group: "test-group", | ||
| Name: "test-property", | ||
| Value: "updated-value", | ||
| Type: "STRING", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "test-group", updated.Group) | ||
| require.Equal(t, "test-property", updated.Name) | ||
| require.Equal(t, "updated-value", updated.Value) | ||
| require.Equal(t, "STRING", updated.Type) | ||
| } | ||
|
|
||
| func TestProjectPropertyService_Delete(t *testing.T) { | ||
| client := setUpContainer(t, testContainerOptions{ | ||
| APIPermissions: []string{ | ||
| PermissionPortfolioManagement, | ||
| }, | ||
| }) | ||
|
|
||
| po := PageOptions{PageSize: 10} | ||
|
|
||
| project, err := client.Project.Create(context.Background(), Project{ | ||
| Name: "acme-app", | ||
| Version: "1.0.0", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Create a property | ||
| _, err = client.ProjectProperty.Create(context.Background(), project.UUID, ProjectProperty{ | ||
| Group: "test-group", | ||
| Name: "test-property", | ||
| Value: "test-value", | ||
| Type: "STRING", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify presence | ||
| properties, err := client.ProjectProperty.GetAll(context.Background(), project.UUID, po) | ||
| require.NoError(t, err) | ||
| require.Len(t, properties.Items, 1) | ||
|
|
||
| // Delete the property | ||
| err = client.ProjectProperty.Delete(context.Background(), project.UUID, "test-group", "test-property") | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify absence | ||
| properties, err = client.ProjectProperty.GetAll(context.Background(), project.UUID, po) | ||
| require.NoError(t, err) | ||
| require.Len(t, properties.Items, 0) | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.