mirror of https://github.com/docker/compose.git
Add test for the backtracking of lines
This commit is contained in:
parent
e852e8f96a
commit
d3f1209bab
22
azure/aci.go
22
azure/aci.go
|
@ -265,23 +265,29 @@ func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroup
|
||||||
b = b.Up(uint(numLines))
|
b = b.Up(uint(numLines))
|
||||||
fmt.Fprint(out, b.Column(0).ANSI)
|
fmt.Fprint(out, b.Column(0).ANSI)
|
||||||
|
|
||||||
|
numLines = getBacktrackLines(logLines, terminalWidth)
|
||||||
|
|
||||||
for i := 0; i < currentOutput-1; i++ {
|
for i := 0; i < currentOutput-1; i++ {
|
||||||
fmt.Fprintln(out, logLines[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)
|
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) {
|
func getContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
|
||||||
containerGroupsClient := containerinstance.NewContainerGroupsClient(subscriptionID)
|
containerGroupsClient := containerinstance.NewContainerGroupsClient(subscriptionID)
|
||||||
err := setupClient(&containerGroupsClient.Client)
|
err := setupClient(&containerGroupsClient.Client)
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
Loading…
Reference in New Issue