Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

perf(cli): optimize CPU consumption of help pages#9607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ammario merged 1 commit intomainfrompr9607
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionscli/clitest/clitest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ import (

// New creates a CLI instance with a configuration pointed to a
// temporary testing directory.
func New(t*testing.T, args ...string) (*clibase.Invocation, config.Root) {
func New(t testing.TB, args ...string) (*clibase.Invocation, config.Root) {
var root cli.RootCmd

cmd, err := root.Command(root.AGPL())
Expand All@@ -56,7 +56,7 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
}

func NewWithCommand(
t*testing.T, cmd *clibase.Cmd, args ...string,
t testing.TB, cmd *clibase.Cmd, args ...string,
) (*clibase.Invocation, config.Root) {
configDir := config.Root(t.TempDir())
logger := slogtest.Make(t, nil)
Expand Down
8 changes: 1 addition & 7 deletionscli/clitest/golden.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,11 +11,9 @@ import (
"strings"
"testing"

"github.com/muesli/termenv"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/config"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
Expand DownExpand Up@@ -50,12 +48,8 @@ func DefaultCases() []CommandHelpCase {

// TestCommandHelp will test the help output of the given commands
// using golden files.
//
//nolint:tparallel,paralleltest
func TestCommandHelp(t *testing.T, getRoot func(t *testing.T) *clibase.Cmd, cases []CommandHelpCase) {
// ANSI256 escape codes are far easier for humans to parse in a diff,
// but TrueColor is probably more popular with modern terminals.
cliui.TestColor(t, termenv.ANSI)
t.Parallel()
rootClient, replacements := prepareTestData(t)

root := getRoot(t)
Expand Down
2 changes: 1 addition & 1 deletioncli/cliui/agent_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:]
Expand Down
37 changes: 19 additions & 18 deletionscli/cliui/cliui.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
package cliui

import (
"flag"
"os"
"testing"
"sync"
"time"

"github.com/muesli/termenv"
Expand DownExpand Up@@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletioncli/cliui/resources_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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))
})
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp