Skip to content

Commit

Permalink
refactor: add test case for duplicate prefixes & remove redundant che…
Browse files Browse the repository at this point in the history
…ck on duplicate project name
  • Loading branch information
corban-beaird committed Apr 18, 2024
1 parent b80d6c4 commit 23446b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 0 additions & 3 deletions master/internal/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,6 @@ func (a *apiServer) PostProject(
if strings.Contains(err.Error(), "projects_key_key") {
return nil,
status.Errorf(codes.AlreadyExists, "project with key %s already exists", projectKey)
} else if strings.Contains(err.Error(), "projects_name_key") {
return nil,
status.Errorf(codes.AlreadyExists, "project with name %s already exists", req.Name)
}
}

Expand Down
21 changes: 21 additions & 0 deletions master/internal/api_project_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,24 @@ func TestCreateProjectWithDuplicateProjectKey(t *testing.T) {
require.Error(t, err)
require.Equal(t, status.Errorf(codes.AlreadyExists, "project with key %s already exists", projectKey), err)
}

func TestCreateProjectWithDefaultKeyAndDuplicatePrefix(t *testing.T) {
api, _, ctx := setupAPITest(t, nil)
wresp, werr := api.PostWorkspace(ctx, &apiv1.PostWorkspaceRequest{Name: uuid.New().String()})
require.NoError(t, werr)

projectName := uuid.New().String()
projectKeyPrefix := projectName[:3]
resp1, err := api.PostProject(ctx, &apiv1.PostProjectRequest{
Name: projectName, WorkspaceId: wresp.Workspace.Id,
})
require.NoError(t, err)
require.Equal(t, (projectKeyPrefix + "1"), resp1.Project.Key)

resp2, err := api.PostProject(ctx, &apiv1.PostProjectRequest{
Name: projectName + "2", WorkspaceId: wresp.Workspace.Id,
})
require.NoError(t, err)
require.NoError(t, err)
require.Equal(t, (projectKeyPrefix + "2"), resp2.Project.Key)
}

0 comments on commit 23446b9

Please sign in to comment.