Skip to content

Commit

Permalink
feat(README, helper): update alias support details and remove unneede…
Browse files Browse the repository at this point in the history
…d helper functions

- Updated README to clarify that account alias is only supported in Kion versions 3.9.9, 3.10.2, and later.
- Removed unneeded helper functions `FindCARByNameAndAccountNumber` and `FindCARByNameAndAlias` from `helper_test.go` and `transform_test.go`, along with their corresponding test cases.
  • Loading branch information
bshutterkion committed Sep 17, 2024
1 parent fa165dd commit 60b976d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 113 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ OPTIONS
--alias val, --aka val, -l val Target account alias, used to bypass
prompts, must be passed with --car.
Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--car val, --cloud-access-role val, Target cloud access role, used to bypass
-c val prompts, must be passed with --account
or --alias.
Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--region val, -r val Specify which region to target.
Expand Down Expand Up @@ -291,9 +295,13 @@ OPTIONS
--alias val, --aka val, -l val Target account alias, used to bypass
prompts, must be passed with --car.
Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--car val, -c val Specify which Cloud Access Role to use,
must be passed with --account or --alias.
Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--region val, -r val Specify which region to target.
Expand All @@ -310,10 +318,13 @@ OPTIONS
--alias val, --aka val, -l val Target account alias, used to bypass
prompts, must be passed with --car.
Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--car val, --cloud-access-role val, Target cloud access role, used to bypass
-c val prompts, must be passed with --account
or --alias.
or --alias. Note account alias only supports
Kion versions 3.9.9 and 3.10.2 and up.
--help, -h Print usage text.
```
Expand Down
22 changes: 0 additions & 22 deletions lib/helper/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package helper

import (
"fmt"

"github.com/kionsoftware/kion-cli/lib/kion"
"github.com/kionsoftware/kion-cli/lib/structs"
)
Expand Down Expand Up @@ -108,23 +106,3 @@ var kionTestFavoritesNames = []string{
// Helpers //
// //
////////////////////////////////////////////////////////////////////////////////

// FindCARByNameAndAccountNumber finds a CAR by name and account number.
func FindCARByNameAndAccountNumber(cars []kion.CAR, name string, accountNumber string) (*kion.CAR, error) {
for _, car := range cars {
if car.Name == name && car.AccountNumber == accountNumber {
return &car, nil
}
}
return nil, fmt.Errorf("cannot find cloud access role with name %v and account number %v", name, accountNumber)
}

// FindCARByNameAndAlias finds a CAR by name and account alias.
func FindCARByNameAndAlias(cars []kion.CAR, name string, accountAlias string) (*kion.CAR, error) {
for _, car := range cars {
if car.Name == name && car.AccountAlias == accountAlias {
return &car, nil
}
}
return nil, fmt.Errorf("cannot find cloud access role with name %v and account alias %v", name, accountAlias)
}
90 changes: 0 additions & 90 deletions lib/helper/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,93 +239,3 @@ func TestFindCARByName(t *testing.T) {
})
}
}

func TestFindCARByNameAndAccountNumber(t *testing.T) {
tests := []struct {
name string
carName string
accountNumber string
cars []kion.CAR
wantCAR *kion.CAR
wantErr error
}{
{
"Find Match",
"car one",
"111111111111",
kionTestCARs,
&kionTestCARs[0],
nil,
},
{
"Find No Match - Wrong Account Number",
"car one",
"999999999999",
kionTestCARs,
nil,
fmt.Errorf("cannot find cloud access role with name %v and account number %v", "car one", "999999999999"),
},
{
"Find No Match - Wrong CAR Name",
"fake car",
"111111111111",
kionTestCARs,
nil,
fmt.Errorf("cannot find cloud access role with name %v and account number %v", "fake car", "111111111111"),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
car, err := FindCARByNameAndAccountNumber(test.cars, test.carName, test.accountNumber)
if !reflect.DeepEqual(test.wantCAR, car) || (err != nil && err.Error() != test.wantErr.Error()) {
t.Errorf("\ngot:\n %v\n %v\nwanted:\n %v\n %v", car, err, test.wantCAR, test.wantErr)
}
})
}
}

func TestFindCARByNameAndAlias(t *testing.T) {
tests := []struct {
name string
carName string
accountAlias string
cars []kion.CAR
wantCAR *kion.CAR
wantErr error
}{
{
"Find Match",
"car two",
"acct-two-alias",
kionTestCARs,
&kionTestCARs[1],
nil,
},
{
"Find No Match - Wrong Account Alias",
"car two",
"non-existent-alias",
kionTestCARs,
nil,
fmt.Errorf("cannot find cloud access role with name %v and account alias %v", "car two", "non-existent-alias"),
},
{
"Find No Match - Wrong CAR Name",
"fake car",
"acct-two-alias",
kionTestCARs,
nil,
fmt.Errorf("cannot find cloud access role with name %v and account alias %v", "fake car", "acct-two-alias"),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
car, err := FindCARByNameAndAlias(test.cars, test.carName, test.accountAlias)
if !reflect.DeepEqual(test.wantCAR, car) || (err != nil && err.Error() != test.wantErr.Error()) {
t.Errorf("\ngot:\n %v\n %v\nwanted:\n %v\n %v", car, err, test.wantCAR, test.wantErr)
}
})
}
}

0 comments on commit 60b976d

Please sign in to comment.