Skip to content

Commit

Permalink
Fixes comments and few function names
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-dass committed Nov 17, 2020
1 parent 7aca2f6 commit 74d9029
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
12 changes: 6 additions & 6 deletions pkg/occlient/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"k8s.io/klog"
)

// GetProject returns project based on the name of the project.Errors related to
// project not being found or forbidden are translated to nil project for compatibility
// GetProject returns project based on the name of the project
// errors related to project not being found or forbidden are translated to nil project for compatibility
func (c *Client) GetProject(projectName string) (*projectv1.Project, error) {
prj, err := c.projectClient.Projects().Get(projectName, metav1.GetOptions{})
if err != nil {
Expand All @@ -40,8 +40,8 @@ func (c *Client) ListProjects() (*projectv1.ProjectList, error) {
return c.projectClient.Projects().List(metav1.ListOptions{})
}

// GetProjectNames return list of existing project names that user has access to.
func (c *Client) GetProjectNames() ([]string, error) {
// ListProjectNames return list of existing project names that user has access to.
func (c *Client) ListProjectNames() ([]string, error) {
projects, err := c.ListProjects()
if err != nil {
return nil, errors.Wrap(err, "unable to list projects")
Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *Client) DeleteProject(name string, wait bool) error {
// CreateNewProject creates project with given projectName
func (c *Client) CreateNewProject(projectName string, wait bool) error {
// Instantiate watcher before requesting new project
// If watched is created after the project it can lead to situation when the project is created before the watcher.
// If watcher is created after the project it can lead to situation when the project is created before the watcher.
// When this happens, it gets stuck waiting for event that already happened.
var watcher watch.Interface
var err error
Expand Down Expand Up @@ -220,7 +220,7 @@ func (c *Client) GetCurrentProjectName() string {
func (c *Client) SetCurrentProject(projectName string) error {
rawConfig, err := c.KubeConfig.RawConfig()
if err != nil {
return errors.Wrapf(err, "unable to switch to %s project", projectName)
return err
}

rawConfig.Contexts[rawConfig.CurrentContext].Namespace = projectName
Expand Down
13 changes: 4 additions & 9 deletions pkg/occlient/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ func TestCreateNewProject(t *testing.T) {
wait: true,
wantErr: false,
},
// {
// name: "Case 2: empty project name",
// projName: "",
// wantErr: true,
// },
}

for _, tt := range tests {
Expand Down Expand Up @@ -148,7 +143,7 @@ func TestListProjects(t *testing.T) {
}
}

func TestGetProjectNames(t *testing.T) {
func TestListProjectNames(t *testing.T) {
tests := []struct {
name string
returnedProjects *projectv1.ProjectList
Expand Down Expand Up @@ -176,13 +171,13 @@ func TestGetProjectNames(t *testing.T) {
return true, tt.returnedProjects, nil
})

got, err := fkclient.GetProjectNames()
got, err := fkclient.ListProjectNames()
if (err != nil) != tt.wantErr {
t.Errorf("GetProjectNames() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("ListProjectNames() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetProjectNames() got = %v, want %v", got, tt.want)
t.Errorf("ListProjectNames() got = %v, want %v", got, tt.want)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/util/completion/completionhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var FileCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *g
// ProjectNameCompletionHandler provides project name completion
var ProjectNameCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *genericclioptions.Context) (completions []string) {
completions = make([]string, 0)
projects, err := context.Client.GetProjectNames()
projects, err := context.Client.ListProjectNames()
if err != nil {
return completions
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func List(context *genericclioptions.Context) (ProjectList, error) {

var allProjects []string
if projectSupport {
allProjects, err = context.Client.GetProjectNames()
allProjects, err = context.Client.ListProjectNames()
if err != nil {
return ProjectList{}, errors.Wrap(err, "cannot get all the projects")
}
Expand Down

0 comments on commit 74d9029

Please sign in to comment.