Skip to content

Commit

Permalink
fix: Add new line while inspecting file contents (#1477)
Browse files Browse the repository at this point in the history
## Description:
<!-- Describe this change, how it works, and the motivation behind it.
-->
Reader did not include break char (new lines), so the writer contained
no new lines, giving the wrong output on both CLI and EM UI.

## 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 #1417
Closes #1042
  • Loading branch information
victorcolombo committed Oct 6, 2023
1 parent 0546e4c commit 545aa53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/server/api_container/server/api_container_service.go
Expand Up @@ -904,7 +904,7 @@ func getTextRepresentation(reader io.Reader, lineCount int) (*string, error) {
return nil, stacktrace.NewError("File has no text representation because '%v' is not printable", char)
}
}
textRepresentation.WriteString(line)
textRepresentation.WriteString(fmt.Sprintf("%s\n", line))
}

if err := scanner.Err(); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions core/server/api_container/server/api_container_service_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec"
"github.com/stretchr/testify/require"
"strings"
"testing"
)

Expand All @@ -35,3 +36,17 @@ func TestOneToOneApiAndPortSpecProtoMapping(t *testing.T) {
seenPortSpecProtos[portSpecProto] = apiPortProto
}
}

func TestGetTextRepresentation(t *testing.T) {
input := `my
line
input
`
expectedOutput := `my
line
`
output, err := getTextRepresentation(strings.NewReader(input), 2)
require.NoError(t, err)
require.NotNil(t, output)
require.Equal(t, expectedOutput, *output)
}
Expand Up @@ -23,7 +23,7 @@ const (
archiveDirectoryTestPattern = "upload-test-golang-"
archiveSubDirectoryTestPattern = "sub-folder-"
archiveFileTestPattern = "test-file-"
archiveTestFileContent = "This file is for testing purposes."
archiveTestFileContent = "This file is for testing purposes.\n"

numberOfTempTestFilesToCreateInSubDir = 3
numberOfTempTestFilesToCreateInArchiveDir = 1
Expand Down

0 comments on commit 545aa53

Please sign in to comment.