Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions cmd/internal/agentcontainer/setup_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ import (
"github.com/stretchr/testify/require"
)

func ptr(s string) *string { return &s }

func TestCompressSetupInfoPreservesSubstitutedValues(t *testing.T) {
// Simulate post-substitution state: PATH is a real value, not a
// ${containerEnv:PATH} literal.
info := &config.Result{
MergedConfig: &config.MergedDevContainerConfig{
DevContainerConfigBase: config.DevContainerConfigBase{
RemoteEnv: map[string]*string{
"PATH": ptr("/usr/local/bin:/usr/bin:/bin"),
"HOME": ptr("/home/testuser"),
"PATH": new("/usr/local/bin:/usr/bin:/bin"),
"HOME": new("/home/testuser"),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func Tunnel(ctx context.Context, opts TunnelOptions) error {
IsLocal: false,
RemoteAgentPath: config.ContainerDevsyHelperLocation,
DownloadURL: config.DefaultAgentDownloadURL(),
PreferDownloadFromRemoteUrl: Bool(false),
PreferDownloadFromRemoteUrl: new(false),
Timeout: opts.Timeout,
}); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/delivery/legacy_shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (d *LegacyShellDelivery) DeliverPostStart(ctx context.Context, opts PostSta
IsLocal: false,
RemoteAgentPath: pkgconfig.ContainerDevsyHelperLocation,
DownloadURL: d.downloadURL(),
PreferDownloadFromRemoteUrl: agent.Bool(false),
PreferDownloadFromRemoteUrl: new(false),
}

if d.Timeout != nil {
Expand Down
11 changes: 6 additions & 5 deletions pkg/agent/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ func (o *InjectOptions) ApplyDefaults() {
o.applyPreferDownloadDefaults()
}

//go:fix inline
func Bool(b bool) *bool {
return &b
return new(b)
}

func (o *InjectOptions) Validate() error {
Expand Down Expand Up @@ -141,13 +142,13 @@ func (o *InjectOptions) applyPreferDownloadDefaults() {
case preferDownloadEnv != "":
o.applyEnvPreference(preferDownloadEnv)
case hasCustomAgentURL:
o.PreferDownloadFromRemoteUrl = Bool(true)
o.PreferDownloadFromRemoteUrl = new(true)
o.SkipVersionCheck = true
case version.GetVersion() == version.DevVersion:
o.PreferDownloadFromRemoteUrl = Bool(false)
o.PreferDownloadFromRemoteUrl = new(false)
o.SkipVersionCheck = true
default:
o.PreferDownloadFromRemoteUrl = Bool(true)
o.PreferDownloadFromRemoteUrl = new(true)
}
}

Expand All @@ -157,7 +158,7 @@ func (o *InjectOptions) applyEnvPreference(preferDownloadEnv string) {
log.Warnf("failed to parse %s, using default", config.EnvAgentPreferDownload)
pref = true
}
o.PreferDownloadFromRemoteUrl = Bool(pref)
o.PreferDownloadFromRemoteUrl = new(pref)
o.SkipVersionCheck = true
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/devcontainer/config/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,3 @@ func TestExtends_LocalWorkspaceFolderBasenameInPath(t *testing.T) {
t.Errorf("expected image 'alpine:3', got %q", cfg.Image)
}
}

//go:fix inline
func strPtr(s string) *string {
return new(s)
}
8 changes: 3 additions & 5 deletions pkg/devcontainer/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,11 @@ func searchString(s, substr string) bool {
return false
}

func strPtr(s string) *string { return &s }

func TestGetWorkspace_CustomWorkspaceMount(t *testing.T) {
customMount := "type=bind,source=/host/src,target=/custom-ws"
conf := &config.DevContainerConfig{
NonComposeBase: config.NonComposeBase{
WorkspaceMount: strPtr(customMount),
WorkspaceMount: new(customMount),
},
}

Expand Down Expand Up @@ -205,7 +203,7 @@ func TestGetWorkspace_DefaultMountWithWorkspaceFolder(t *testing.T) {
func TestGetWorkspace_EmptyWorkspaceMount(t *testing.T) {
conf := &config.DevContainerConfig{
NonComposeBase: config.NonComposeBase{
WorkspaceMount: strPtr(""),
WorkspaceMount: new(""),
},
}

Expand Down Expand Up @@ -236,7 +234,7 @@ func TestGetWorkspace_UserConsistencyPreserved(t *testing.T) {
customMount := "type=bind,source=/src,target=/ws,consistency=delegated"
conf := &config.DevContainerConfig{
NonComposeBase: config.NonComposeBase{
WorkspaceMount: strPtr(customMount),
WorkspaceMount: new(customMount),
},
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/devcontainer/setup/lifecyclehooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ func makeTestPhaseHooks() []phaseHook {
}
}

func ptr(s string) *string { return &s }

func (s *LifecycleHookTestSuite) TestMergeRemoteEnvNilUnsetsKey() {
probedEnv := map[string]string{"KEEP": "yes", "DROP": "bye"}
remoteEnv := map[string]*string{"DROP": nil}
Expand All @@ -290,7 +288,7 @@ func (s *LifecycleHookTestSuite) TestMergeRemoteEnvNilUnsetsKey() {

func (s *LifecycleHookTestSuite) TestMergeRemoteEnvNonNilOverrides() {
probedEnv := map[string]string{"VAR": "old"}
remoteEnv := map[string]*string{"VAR": ptr("new")}
remoteEnv := map[string]*string{"VAR": new("new")}

result := mergeRemoteEnv(remoteEnv, probedEnv, "vscode")

Expand Down
6 changes: 2 additions & 4 deletions pkg/devcontainer/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/devsy-org/devsy/pkg/types"
)

func boolPtr(v bool) *bool { return &v }

func TestShouldChownWorkspace(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -98,12 +96,12 @@ func TestResolvePullFromInsideContainer(t *testing.T) {
}{
{
name: "override true wins",
opts: provider2.CLIOptions{PullFromInsideContainerOverride: boolPtr(true)},
opts: provider2.CLIOptions{PullFromInsideContainerOverride: new(true)},
want: types.StrBool(stringTrue),
},
{
name: "override false wins even with git source",
opts: provider2.CLIOptions{PullFromInsideContainerOverride: boolPtr(false)},
opts: provider2.CLIOptions{PullFromInsideContainerOverride: new(false)},
repo: "https://github.com/example/repo",
want: types.StrBool(stringFalse),
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/dockerfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dockerfile
import (
"fmt"
"regexp"
"slices"
"strings"

"github.com/devsy-org/devsy/pkg/scanner"
Expand Down Expand Up @@ -185,8 +186,8 @@ func (d *Dockerfile) resolveFromArgs(
variable string,
stage *BaseStage,
) (string, bool) {
for i := len(stage.Args) - 1; i >= 0; i-- {
arg := &stage.Args[i]
for _, v := range slices.Backward(stage.Args) {
arg := &v
if arg.Key != variable {
continue
}
Expand All @@ -206,8 +207,8 @@ func (d *Dockerfile) resolveFromEnvs(
variable string,
stage *BaseStage,
) (string, bool) {
for i := len(stage.Envs) - 1; i >= 0; i-- {
env := &stage.Envs[i]
for _, v := range slices.Backward(stage.Envs) {
env := &v
if env.Key != variable {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/machineid/id_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ID() (string, error) {
if err != nil {
return "", fmt.Errorf("ioreg: %w", err)
}
for _, line := range strings.Split(string(out), "\n") {
for line := range strings.SplitSeq(string(out), "\n") {
if strings.Contains(line, "IOPlatformUUID") {
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func InheritFromEnvironment(
func assignedNames(assignments []string) map[string]bool {
names := make(map[string]bool, len(assignments))
for _, assignment := range assignments {
if idx := strings.Index(assignment, "="); idx != -1 {
names[assignment[:idx]] = true
if before, _, ok := strings.Cut(assignment, "="); ok {
names[before] = true
}
}
return names
Expand Down
4 changes: 2 additions & 2 deletions pkg/ts/derp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func GetEnvOrDefault(envVar, defaultVal string) string {

// RemoveProtocol removes protocol from URL.
func RemoveProtocol(hostPath string) string {
if idx := strings.Index(hostPath, "://"); idx != -1 {
return hostPath[idx+3:]
if _, after, ok := strings.Cut(hostPath, "://"); ok {
return after
}
return hostPath
}
12 changes: 5 additions & 7 deletions pkg/workspace/rename_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ func loadWorkspaceResult(
return result
}

func ptrStr(s string) *string { return &s }

func TestUpdateWorkspaceResult_BasicRename(t *testing.T) {
setupTestPathManager(t)

Expand All @@ -73,7 +71,7 @@ func TestUpdateWorkspaceResult_BasicRename(t *testing.T) {
MergedConfig: &devcontainerconfig.MergedDevContainerConfig{},
}
result.MergedConfig.WorkspaceFolder = "/workspaces/my-project"
result.MergedConfig.WorkspaceMount = ptrStr(
result.MergedConfig.WorkspaceMount = new(
"type=bind,source=/home/user/my-project,target=/workspaces/my-project",
)

Expand Down Expand Up @@ -109,7 +107,7 @@ func TestUpdateWorkspaceResult_MergedConfigUpdated(t *testing.T) {
MergedConfig: &devcontainerconfig.MergedDevContainerConfig{},
}
result.MergedConfig.WorkspaceFolder = "/workspaces/app"
result.MergedConfig.WorkspaceMount = ptrStr(
result.MergedConfig.WorkspaceMount = new(
"type=bind,source=/home/dev/app,target=/workspaces/app",
)

Expand Down Expand Up @@ -145,7 +143,7 @@ func TestUpdateWorkspaceResult_NonDefaultWorkspaceDir(t *testing.T) {
MergedConfig: &devcontainerconfig.MergedDevContainerConfig{},
}
result.MergedConfig.WorkspaceFolder = "/home/coder/project"
result.MergedConfig.WorkspaceMount = ptrStr(
result.MergedConfig.WorkspaceMount = new(
"type=bind,source=/mnt/data/project,target=/home/coder/project",
)

Expand Down Expand Up @@ -187,7 +185,7 @@ func TestUpdateWorkspaceResult_NestedPath(t *testing.T) {
MergedConfig: &devcontainerconfig.MergedDevContainerConfig{},
}
result.MergedConfig.WorkspaceFolder = "/workspaces/org/repo"
result.MergedConfig.WorkspaceMount = ptrStr(
result.MergedConfig.WorkspaceMount = new(
"type=bind,source=/home/user/dev/org/repo,target=/workspaces/org/repo",
)

Expand Down Expand Up @@ -220,7 +218,7 @@ func TestUpdateWorkspaceResult_SameNameIdempotent(t *testing.T) {
MergedConfig: &devcontainerconfig.MergedDevContainerConfig{},
}
result.MergedConfig.WorkspaceFolder = "/workspaces/my-ws"
result.MergedConfig.WorkspaceMount = ptrStr(
result.MergedConfig.WorkspaceMount = new(
"type=bind,source=/home/user/my-ws,target=/workspaces/my-ws",
)

Expand Down
Loading