mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
perf(cli): optimize CPU consumption of help pages (#9607)
This change reduces the CPU consumption of --help by ~50%. Also, this change removes ANSI escape codes from our golden files. I don't think those were worth the inability to parallelize golden file tests and global state fragility.
This commit is contained in:
@@ -340,7 +340,7 @@ func TestAgent(t *testing.T) {
|
||||
line := s.Text()
|
||||
t.Log(line)
|
||||
if len(tc.want) == 0 {
|
||||
require.Fail(t, "unexpected line: "+line)
|
||||
require.Fail(t, "unexpected line", line)
|
||||
}
|
||||
require.Contains(t, line, tc.want[0])
|
||||
tc.want = tc.want[1:]
|
||||
|
||||
+19
-18
@@ -1,8 +1,9 @@
|
||||
package cliui
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
@@ -30,29 +31,29 @@ type Styles struct {
|
||||
Wrap pretty.Style
|
||||
}
|
||||
|
||||
var color = termenv.NewOutput(os.Stdout).ColorProfile()
|
||||
|
||||
// TestColor sets the color profile to the given profile for the duration of the
|
||||
// test.
|
||||
// WARN: Must not be used in parallel tests.
|
||||
func TestColor(t *testing.T, tprofile termenv.Profile) {
|
||||
old := color
|
||||
color = tprofile
|
||||
t.Cleanup(func() {
|
||||
color = old
|
||||
})
|
||||
}
|
||||
var (
|
||||
color termenv.Profile
|
||||
colorOnce sync.Once
|
||||
)
|
||||
|
||||
var (
|
||||
Green = color.Color("#04B575")
|
||||
Red = color.Color("#ED567A")
|
||||
Fuchsia = color.Color("#EE6FF8")
|
||||
Yellow = color.Color("#ECFD65")
|
||||
Blue = color.Color("#5000ff")
|
||||
Green = Color("#04B575")
|
||||
Red = Color("#ED567A")
|
||||
Fuchsia = Color("#EE6FF8")
|
||||
Yellow = Color("#ECFD65")
|
||||
Blue = Color("#5000ff")
|
||||
)
|
||||
|
||||
// Color returns a color for the given string.
|
||||
func Color(s string) termenv.Color {
|
||||
colorOnce.Do(func() {
|
||||
color = termenv.NewOutput(os.Stdout).ColorProfile()
|
||||
if flag.Lookup("test.v") != nil {
|
||||
// Use a consistent colorless profile in tests so that results
|
||||
// are deterministic.
|
||||
color = termenv.Ascii
|
||||
}
|
||||
})
|
||||
return color.Color(s)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestRenderAgentVersion(t *testing.T) {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
actual := renderAgentVersion(testCase.agentVersion, testCase.serverVersion)
|
||||
assert.Equal(t, testCase.expected, actual)
|
||||
assert.Equal(t, testCase.expected, (actual))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user