Add test for the backtracking of lines

This commit is contained in:
Djordje Lukic 2020-07-02 11:11:09 +02:00
parent e852e8f96a
commit d3f1209bab
2 changed files with 26 additions and 8 deletions

View File

@ -265,23 +265,29 @@ func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroup
b = b.Up(uint(numLines))
fmt.Fprint(out, b.Column(0).ANSI)
numLines = getBacktrackLines(logLines, terminalWidth)
for i := 0; i < currentOutput-1; i++ {
fmt.Fprintln(out, logLines[i])
}
numLines = 0
for i := 0; i < currentOutput-1; i++ {
numLines++
if len(logLines[i]) > terminalWidth {
numLines += len(logLines[i]) / terminalWidth
}
}
time.Sleep(2 * time.Second)
}
}
}
func getBacktrackLines(lines []string, terminalWidth int) int {
numLines := 0
for i := 0; i < len(lines)-1; i++ {
numLines++
if len(lines[i]) > terminalWidth {
numLines += len(lines[i]) / terminalWidth
}
}
return numLines
}
func getContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
containerGroupsClient := containerinstance.NewContainerGroupsClient(subscriptionID)
err := setupClient(&containerGroupsClient.Client)

12
azure/aci_test.go Normal file
View File

@ -0,0 +1,12 @@
package azure
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetLinesWritten(t *testing.T) {
assert.Equal(t, 0, getBacktrackLines([]string{"Hello"}, 10))
assert.Equal(t, 3, getBacktrackLines([]string{"Hello", "world"}, 2))
}