Skip to content

Commit

Permalink
Fix oc to odo project translation (#6949)
Browse files Browse the repository at this point in the history
* Fix oc to odo project translation

Signed-off-by: Parthvi <[email protected]>

* Attempt at fixing regression

Signed-off-by: Parthvi <[email protected]>

* Add unit test for filteredInformation

Signed-off-by: Parthvi <[email protected]>

* Use oc command instead of odo

Signed-off-by: Parthvi <[email protected]>
Co-authored-by: Armel Soro <[email protected]>

---------

Signed-off-by: Parthvi <[email protected]>
Co-authored-by: Parthvi Vala <[email protected]>
Co-authored-by: Armel Soro <[email protected]>
  • Loading branch information
3 people authored Jul 17, 2023
1 parent 01a1484 commit abc808b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (o KubernetesClient) Login(server, username, password, token, caAuth string

a := login.LoginOptions{
Server: server,
CommandName: "odo",
CommandName: "oc",
CAFile: caAuth,
InsecureTLS: skipTLS,
Username: username,
Expand Down Expand Up @@ -143,9 +143,8 @@ func filteredInformation(s []byte) []byte {

// List of strings to correctly filter
s = bytes.Replace(s, []byte("oc new-project"), []byte("odo create project"), -1)
s = bytes.Replace(s, []byte("<projectname>"), []byte("<project-name>"), -1)
s = bytes.Replace(s, []byte("project <project-name>"), []byte("project set <project-name>"), -1)
s = bytes.Replace(s, []byte("odo projects"), []byte("odo list project"), -1)
s = bytes.Replace(s, []byte("oc project "), []byte("odo set project "), -1)
s = bytes.Replace(s, []byte("oc projects"), []byte("odo list project"), -1)

return s
}
78 changes: 78 additions & 0 deletions pkg/auth/login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package auth

import (
"reflect"
"testing"
)

func Test_filteredInformation(t *testing.T) {
type args struct {
s []byte
}
tests := []struct {
name string
args args
want []byte
}{
{
name: "login with no projects",
args: args{
s: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>`),
},
want: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You don't have any projects. You can try to create a new project, by running
odo create project <projectname>`),
},
{
name: "login with only 1 project",
args: args{
s: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You have one project on this server: "test1"
Using project "test1".`),
},
want: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You have one project on this server: "test1"
Using project "test1".`),
},
{
name: "login with more than one project",
args: args{
s: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You have access to the following projects and can switch between them with 'oc project <projectname>':
test1
test2
* test3
Using project "test3".`),
},
want: []byte(`Logged into "https://api.crc.testing:6443" as "developer" using existing credentials.
You have access to the following projects and can switch between them with 'odo set project <projectname>':
test1
test2
* test3
Using project "test3".`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := filteredInformation(tt.args.s); !reflect.DeepEqual(got, tt.want) {
t.Errorf("filteredInformation() = %v\nwant = %v", string(got), string(tt.want))
}
})
}
}

0 comments on commit abc808b

Please sign in to comment.