Skip to content

Commit

Permalink
Use go:embed for pingpong script
Browse files Browse the repository at this point in the history
This makes the test independent from its working directory.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed May 20, 2024
1 parent 326a7f0 commit b54c097
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/supervisor/pingpong_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ limitations under the License.
package supervisor

import (
_ "embed"
"io"
"net"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/k0sproject/k0s/internal/pkg/file"

"github.com/Microsoft/go-winio"
"github.com/Microsoft/go-winio/pkg/guid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/multierr"
)

//go:embed pingpong.ps1
var script []byte

type pingPong struct {
shellPath string
shellArgs []string
Expand All @@ -43,9 +46,8 @@ func makePingPong(t *testing.T) *pingPong {
shellPath, err := exec.LookPath("powershell")
require.NoError(t, err)

// We need that copy, otherwise tests get cached.
scriptPath := filepath.Join(t.TempDir(), "pingpong.ps1")
require.NoError(t, file.Copy("pingpong.ps1", scriptPath))
require.NoError(t, os.WriteFile(scriptPath, script, 0700))

guid, err := guid.NewV4()
require.NoError(t, err)
Expand Down

0 comments on commit b54c097

Please sign in to comment.