@@ -511,26 +511,40 @@ func TestEndpoint_ValidateAndSetDefaultsWithSSH(t *testing.T) {
511511 name string
512512 username string
513513 password string
514+ privateKey string
514515 expectedErr error
515516 }{
516517 {
517- name : "fail when has no user" ,
518+ name : "fail when has no user but has password " ,
518519 username : "" ,
519520 password : "password" ,
520521 expectedErr : ssh .ErrEndpointWithoutSSHUsername ,
521522 },
522523 {
523- name : "fail when has no password" ,
524+ name : "fail when has no user but has private key" ,
525+ username : "" ,
526+ privateKey : "-----BEGIN" ,
527+ expectedErr : ssh .ErrEndpointWithoutSSHUsername ,
528+ },
529+ {
530+ name : "fail when has no password or private key" ,
524531 username : "username" ,
525532 password : "" ,
533+ privateKey : "" ,
526534 expectedErr : ssh .ErrEndpointWithoutSSHAuth ,
527535 },
528536 {
529- name : "success when all fields are set" ,
537+ name : "success when username and password are set" ,
530538 username : "username" ,
531539 password : "password" ,
532540 expectedErr : nil ,
533541 },
542+ {
543+ name : "success when username and private key are set" ,
544+ username : "username" ,
545+ privateKey : "-----BEGIN" ,
546+ expectedErr : nil ,
547+ },
534548 }
535549
536550 for _ , scenario := range scenarios {
@@ -539,8 +553,9 @@ func TestEndpoint_ValidateAndSetDefaultsWithSSH(t *testing.T) {
539553 Name : "ssh-test" ,
540554 URL : "https://example.com" ,
541555 SSHConfig : & ssh.Config {
542- Username : scenario .username ,
543- Password : scenario .password ,
556+ Username : scenario .username ,
557+ Password : scenario .password ,
558+ PrivateKey : scenario .privateKey ,
544559 },
545560 Conditions : []Condition {Condition ("[STATUS] == 0" )},
546561 }
0 commit comments