From df2ac2734b6d014a3fb6f2e6bc15686baaab7647 Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 11:08:20 +0000 Subject: [PATCH 1/2] test: cover credential helper script gen Add tests for pkg/dockercredentials buildHelperContent covering unix and windows credential-helper script generation: shebang/echo prefix, embedded port, the literal 'internal agent docker-credentials' subcommand, LF vs CRLF line endings, single-quote quoting of binary paths with spaces, and windows percent-doubling. Also covers newDockerCredentialsDir naming/length and appendToPath PATH extension. These functions had zero test coverage; no behavioral change. --- pkg/dockercredentials/helper_content_test.go | 119 +++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 pkg/dockercredentials/helper_content_test.go diff --git a/pkg/dockercredentials/helper_content_test.go b/pkg/dockercredentials/helper_content_test.go new file mode 100644 index 0000000000..9e835f2d47 --- /dev/null +++ b/pkg/dockercredentials/helper_content_test.go @@ -0,0 +1,119 @@ +package dockercredentials + +import ( + "os" + "runtime" + "strconv" + "strings" + "testing" + + "github.com/stretchr/testify/suite" +) + +type HelperContentTestSuite struct { + suite.Suite +} + +func TestHelperContentSuite(t *testing.T) { + suite.Run(t, new(HelperContentTestSuite)) +} + +func (s *HelperContentTestSuite) TestBuildHelperContentUnix() { + if runtime.GOOS == "windows" { + s.T().Skip("unix variant only on non-windows host") + } + + const binaryPath = "/usr/local/bin/devsy" + out := buildHelperContent(binaryPath, "#!/bin/sh", 4242) + content := string(out) + + s.True(strings.HasPrefix(content, "#!/bin/sh\n"), "shebang on its own line") + s.Contains(content, binaryPath) + s.Contains(content, "internal agent docker-credentials") + s.Contains(content, "--port 4242") + s.Contains(content, `"$@"`) + s.True(strings.HasSuffix(content, "\n"), "script must end with newline") + s.NotContains(content, "\r", "unix script uses LF line endings") +} + +func (s *HelperContentTestSuite) TestBuildHelperContentWindows() { + if runtime.GOOS != "windows" { + s.T().Skip("windows variant only on windows host") + } + + const binaryPath = `C:\Program Files\devsy\devsy.exe` + out := buildHelperContent(binaryPath, "@echo off", 9999) + content := string(out) + + s.True(strings.HasPrefix(content, "@echo off\r\n")) + s.Contains(content, `"`+binaryPath+`"`) + s.Contains(content, "internal agent docker-credentials") + s.Contains(content, "--port 9999") + s.Contains(content, "%*") + s.True(strings.HasSuffix(content, "\r\n"), "script must end with CRLF") +} + +func (s *HelperContentTestSuite) TestBuildHelperContentQuotesSpacesInBinaryPath() { + if runtime.GOOS == "windows" { + s.T().Skip("unix quoting variant only on non-windows host") + } + + const binaryPath = "/usr/local/bin/custom devsy" + out := buildHelperContent(binaryPath, "#!/bin/sh", 1) + content := string(out) + + s.Contains(content, `'/usr/local/bin/custom devsy'`) + s.NotContains(content, binaryPath+" internal") +} + +func (s *HelperContentTestSuite) TestBuildHelperContentEscapesWindowsPercent() { + if runtime.GOOS != "windows" { + s.T().Skip("windows percent-escaping only on windows host") + } + + const binaryPath = `C:\apps\devsy 1.0\devsy.exe` + out := buildHelperContent(binaryPath, "@echo off", 7) + content := string(out) + + s.Contains(content, `"`+binaryPath+`"`) + s.Contains(content, "--port 7 %*") +} + +func (s *HelperContentTestSuite) TestBuildHelperContentDoublesWindowsPercentInPath() { + if runtime.GOOS != "windows" { + s.T().Skip("windows percent-doubling only on windows host") + } + + const binaryPath = `C:\%USERNAME%\devsy.exe` + out := buildHelperContent(binaryPath, "@echo off", 7) + content := string(out) + + s.Contains(content, `"`+strings.ReplaceAll(binaryPath, "%", "%%")+`"`) + s.NotContains(content, `"%USERNAME%`) +} + +func (s *HelperContentTestSuite) TestBuildHelperContentEmbedsPort() { + for _, port := range []int{0, 1, 65535} { + out := buildHelperContent("/usr/local/bin/devsy", "#!/bin/sh", port) + s.Contains(string(out), strconv.Itoa(port)) + } +} + +func (s *HelperContentTestSuite) TestNewDockerCredentialsDirStructure() { + const suffixLen = 12 + dir := newDockerCredentialsDir("/tmp/parent") + + s.Equal("/tmp/parent/docker-credentials-", dir[:len("/tmp/parent/docker-credentials-")]) + s.Len(dir, len("/tmp/parent/docker-credentials-")+suffixLen) +} + +func (s *HelperContentTestSuite) TestAppendToPathAddsDir() { + orig := os.Getenv("PATH") + s.T().Cleanup(func() { os.Setenv("PATH", orig) }) + + s.NoError(os.Setenv("PATH", "/usr/bin")) + s.NoError(appendToPath("/opt/bin")) + + parts := strings.Split(os.Getenv("PATH"), ":") + s.Equal([]string{"/usr/bin", "/opt/bin"}, parts) +} From ab3a84f62e0533d1e7a5128c8a35eecd92834e5f Mon Sep 17 00:00:00 2001 From: Samuel K Date: Tue, 11 Aug 2026 05:10:12 +0000 Subject: [PATCH 2/2] fix: linting errors Signed-off-by: Samuel K --- pkg/dockercredentials/helper_content_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/dockercredentials/helper_content_test.go b/pkg/dockercredentials/helper_content_test.go index 9e835f2d47..c29cfa34b3 100644 --- a/pkg/dockercredentials/helper_content_test.go +++ b/pkg/dockercredentials/helper_content_test.go @@ -19,7 +19,7 @@ func TestHelperContentSuite(t *testing.T) { } func (s *HelperContentTestSuite) TestBuildHelperContentUnix() { - if runtime.GOOS == "windows" { + if runtime.GOOS == windowsOS { s.T().Skip("unix variant only on non-windows host") } @@ -37,7 +37,7 @@ func (s *HelperContentTestSuite) TestBuildHelperContentUnix() { } func (s *HelperContentTestSuite) TestBuildHelperContentWindows() { - if runtime.GOOS != "windows" { + if runtime.GOOS != windowsOS { s.T().Skip("windows variant only on windows host") } @@ -54,7 +54,7 @@ func (s *HelperContentTestSuite) TestBuildHelperContentWindows() { } func (s *HelperContentTestSuite) TestBuildHelperContentQuotesSpacesInBinaryPath() { - if runtime.GOOS == "windows" { + if runtime.GOOS == windowsOS { s.T().Skip("unix quoting variant only on non-windows host") } @@ -67,7 +67,7 @@ func (s *HelperContentTestSuite) TestBuildHelperContentQuotesSpacesInBinaryPath( } func (s *HelperContentTestSuite) TestBuildHelperContentEscapesWindowsPercent() { - if runtime.GOOS != "windows" { + if runtime.GOOS != windowsOS { s.T().Skip("windows percent-escaping only on windows host") } @@ -80,7 +80,7 @@ func (s *HelperContentTestSuite) TestBuildHelperContentEscapesWindowsPercent() { } func (s *HelperContentTestSuite) TestBuildHelperContentDoublesWindowsPercentInPath() { - if runtime.GOOS != "windows" { + if runtime.GOOS != windowsOS { s.T().Skip("windows percent-doubling only on windows host") } @@ -109,7 +109,7 @@ func (s *HelperContentTestSuite) TestNewDockerCredentialsDirStructure() { func (s *HelperContentTestSuite) TestAppendToPathAddsDir() { orig := os.Getenv("PATH") - s.T().Cleanup(func() { os.Setenv("PATH", orig) }) + s.T().Cleanup(func() { _ = os.Setenv("PATH", orig) }) s.NoError(os.Setenv("PATH", "/usr/bin")) s.NoError(appendToPath("/opt/bin"))