-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve UX when using port print format string (#1359)
## Description: <!-- Describe this change, how it works, and the motivation behind it. --> This PR introduces: - Argument order validation check - Custom formatting when only one value is specified on format string - Unit tests for formatting functions - CI test for the CLI command This PR also fixes the default flag of the command ## Is this change user facing? YES <!-- If yes, please add the "user facing" label to the PR --> <!-- If yes, don't forget to include docs changes where relevant --> ## References (if applicable): <!-- Add relevant Github Issues, Discord threads, or other helpful information. --> Closes #1355 Closes #1356 Closes #1357
- Loading branch information
1 parent
f092bf5
commit 269fe88
Showing
3 changed files
with
79 additions
and
6 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
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,41 @@ | ||
package print | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/services" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const ( | ||
testIpAddress = "127.0.0.1" | ||
port = 123 | ||
applicationProtocol = "http" | ||
transportProtocol = services.TransportProtocol_TCP | ||
) | ||
|
||
var portSpec = services.NewPortSpec(port, transportProtocol, applicationProtocol) | ||
|
||
func TestOnlyPiece(t *testing.T) { | ||
inputExpectedOutputMap := map[string]string{ | ||
"number": fmt.Sprintf("%d", port), | ||
"protocol": applicationProtocol, | ||
"ip": testIpAddress, | ||
} | ||
for in, expected := range inputExpectedOutputMap { | ||
out, err := formatPortOutput(in, testIpAddress, portSpec) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expected, out) | ||
} | ||
} | ||
|
||
func TestAllPieces(t *testing.T) { | ||
out, err := formatPortOutput("protocol,ip,number", testIpAddress, portSpec) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "http://127.0.0.1:123", out) | ||
} | ||
|
||
func TestPiecesOutOfOrder(t *testing.T) { | ||
_, err := formatPortOutput("ip,protocol", testIpAddress, portSpec) | ||
assert.Error(t, err) | ||
} |