-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve error messaging when mandatory flag is missing in file c…
…onvert (#1429) When mandatory flags for file convert are missing, the error message is not helpful. In this commit, we have added additional validation to communicate more details in the message.
- Loading branch information
1 parent
2c9a599
commit 8a293d9
Showing
4 changed files
with
101 additions
and
0 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,56 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_FileConvert(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
convertCmdSourceFormat string | ||
convertCmdDestinationFormat string | ||
errorExpected bool | ||
errorString string | ||
}{ | ||
{ | ||
name: "Valid source and destination format", | ||
convertCmdSourceFormat: "kong-gateway-2.x", | ||
convertCmdDestinationFormat: "kong-gateway-3.x", | ||
errorExpected: false, | ||
}, | ||
{ | ||
name: "Invalid source format", | ||
convertCmdSourceFormat: "random-value", | ||
convertCmdDestinationFormat: "kong-gateway-3.x", | ||
errorExpected: true, | ||
errorString: "invalid value 'random-value' found for the 'from' flag." + | ||
" Allowed values: [kong-gateway, kong-gateway-2.x]", | ||
}, | ||
{ | ||
name: "Invalid destination format", | ||
convertCmdSourceFormat: "kong-gateway-2.x", | ||
convertCmdDestinationFormat: "random-value", | ||
errorExpected: true, | ||
errorString: "invalid value 'random-value' found for the 'to' flag." + | ||
" Allowed values: [konnect, kong-gateway-3.x]", | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
_, err := fileConvert( | ||
"--from", tc.convertCmdSourceFormat, | ||
"--to", tc.convertCmdDestinationFormat, | ||
"--input-file", "testdata/file-convert/001-kong-gateway-config/kong-gateway-2-x.yaml", | ||
) | ||
|
||
if tc.errorExpected { | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), tc.errorString) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
tests/integration/testdata/file-convert/001-kong-gateway-config/kong-gateway-2-x.yaml
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,10 @@ | ||
_format_version: "1.1" | ||
services: | ||
- connect_timeout: 60000 | ||
id: 58076db2-28b6-423b-ba39-a797193017f7 | ||
host: mockbin.org | ||
name: svc1 | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 |