mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-30 02:28:48 -04:00
cli: unify verify/recover endpoint flag
This commit is contained in:
parent
c9226de9ab
commit
3318126363
12 changed files with 114 additions and 61 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsCloudProvider(t *testing.T) {
|
||||
|
@ -36,3 +37,54 @@ func TestIsCloudProvider(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateEndpoint(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
endpoint string
|
||||
defaultPort int
|
||||
wantResult string
|
||||
wantErr bool
|
||||
}{
|
||||
"ip and port": {
|
||||
endpoint: "192.0.2.1:2",
|
||||
defaultPort: 3,
|
||||
wantResult: "192.0.2.1:2",
|
||||
},
|
||||
"hostname and port": {
|
||||
endpoint: "foo:2",
|
||||
defaultPort: 3,
|
||||
wantResult: "foo:2",
|
||||
},
|
||||
"ip": {
|
||||
endpoint: "192.0.2.1",
|
||||
defaultPort: 3,
|
||||
wantResult: "192.0.2.1:3",
|
||||
},
|
||||
"hostname": {
|
||||
endpoint: "foo",
|
||||
defaultPort: 3,
|
||||
wantResult: "foo:3",
|
||||
},
|
||||
"invalid endpoint": {
|
||||
endpoint: "foo:2:2",
|
||||
defaultPort: 3,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
res, err := validateEndpoint(tc.endpoint, tc.defaultPort)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(err)
|
||||
assert.Equal(tc.wantResult, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue