-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: amtinfo display user certificates
- Loading branch information
1 parent
92a8845
commit 8f7fa78
Showing
7 changed files
with
279 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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,92 @@ | ||
package flags | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"rpc/pkg/utils" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestParseFlagsAmtInfo(t *testing.T) { | ||
defaultFlags := AmtInfoFlags{ | ||
Ver: true, | ||
Bld: true, | ||
Sku: true, | ||
UUID: true, | ||
Mode: true, | ||
DNS: true, | ||
Ras: true, | ||
Lan: true, | ||
Hostname: true, | ||
} | ||
|
||
tests := map[string]struct { | ||
cmdLine string | ||
wantResult utils.ReturnCode | ||
wantFlags AmtInfoFlags | ||
userInput string | ||
}{ | ||
"expect success for basic command": { | ||
cmdLine: "./rpc amtinfo -json", | ||
wantResult: utils.Success, | ||
wantFlags: defaultFlags, | ||
}, | ||
"expect IncorrectCommandLineParameters on Parse error": { | ||
cmdLine: "./rpc amtinfo -balderdash", | ||
wantResult: utils.IncorrectCommandLineParameters, | ||
wantFlags: AmtInfoFlags{}, | ||
}, | ||
"expect only cert flag with no password on command line": { | ||
cmdLine: "./rpc amtinfo -cert", | ||
wantResult: utils.Success, | ||
wantFlags: AmtInfoFlags{ | ||
Cert: true, | ||
}, | ||
}, | ||
"expect both cert flags with no password on command line": { | ||
cmdLine: "./rpc amtinfo -cert -password testPassword", | ||
wantResult: utils.Success, | ||
wantFlags: AmtInfoFlags{ | ||
Cert: true, | ||
UserCert: true, | ||
}, | ||
}, | ||
"expect MissingOrIncorrectPassword for userCert": { | ||
cmdLine: "./rpc amtinfo -userCert", | ||
wantResult: utils.MissingOrIncorrectPassword, | ||
wantFlags: AmtInfoFlags{ | ||
UserCert: true, | ||
}, | ||
}, | ||
"expect Success for userCert with password": { | ||
cmdLine: "./rpc amtinfo -userCert -password testPassword", | ||
wantResult: utils.Success, | ||
wantFlags: AmtInfoFlags{ | ||
UserCert: true, | ||
}, | ||
}, | ||
"expect Success for userCert with password input": { | ||
cmdLine: "./rpc amtinfo -userCert", | ||
wantResult: utils.Success, | ||
wantFlags: AmtInfoFlags{ | ||
UserCert: true, | ||
}, | ||
userInput: "testPassword", | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
args := strings.Fields(tc.cmdLine) | ||
if tc.userInput != "" { | ||
defer userInput(t, tc.userInput)() | ||
} | ||
flags := NewFlags(args) | ||
gotResult := flags.ParseFlags() | ||
assert.Equal(t, tc.wantResult, gotResult) | ||
assert.Equal(t, true, flags.Local) | ||
assert.Equal(t, utils.CommandAMTInfo, flags.Command) | ||
assert.Equal(t, tc.wantFlags, flags.AmtInfo) | ||
}) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.