-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from bmc-toolbox/fix-race-condition-creating-…
…sshclient PSM-2322 Fix a race condition in creating SSHClient
- Loading branch information
Showing
23 changed files
with
600 additions
and
765 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,85 @@ | ||
package sshclient | ||
|
||
import "testing" | ||
|
||
func Test_checkAndBuildAddr(t *testing.T) { | ||
type args struct { | ||
addr string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "OK: only IPv4 address", | ||
args: args{ | ||
"127.0.0.1", | ||
}, | ||
want: "127.0.0.1:22", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "OK: only IPv6 address", | ||
args: args{ | ||
"fe80::1", | ||
}, | ||
want: "[fe80::1]:22", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "OK: only host", | ||
args: args{ | ||
"localhost", | ||
}, | ||
want: "localhost:22", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "OK: IPv4 address with port", | ||
args: args{ | ||
"127.0.0.1:2222", | ||
}, | ||
want: "127.0.0.1:2222", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "OK: IPv6 address with port", | ||
args: args{ | ||
"[fe80::1]:2222", | ||
}, | ||
want: "[fe80::1]:2222", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "OK: host with port", | ||
args: args{ | ||
"localhost:2222", | ||
}, | ||
want: "localhost:2222", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Not OK: empty addr", | ||
args: args{ | ||
"", | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := checkAndBuildAddr(tt.args.addr) | ||
t.Log(got) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("checkAndBuildAddr() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("checkAndBuildAddr() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,8 @@ | ||
package internal | ||
|
||
import "unicode" | ||
|
||
// IsntLetterOrNumber check if the give rune is not a letter nor a number | ||
func IsntLetterOrNumber(c rune) bool { | ||
return !unicode.IsLetter(c) && !unicode.IsNumber(c) | ||
} |
Oops, something went wrong.