Skip to content

Commit

Permalink
Merge pull request #13 from amenzhinsky/fix-shell
Browse files Browse the repository at this point in the history
Fix shell
  • Loading branch information
Aliaksandr Mianzhynski authored Mar 20, 2023
2 parents 9e9712f + 41dd86e commit d27e26e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Test and Lint
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
test:
Expand All @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- name: Run Tests
run: go test -v ./...

Expand All @@ -32,9 +32,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
version: v1.52.0
args: --enable=gofumpt,goimports,whitespace,gocritic,exportloopref,unconvert,prealloc
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/amenzhinsky/go-memexec

go 1.17
go 1.19

require golang.org/x/sys v0.0.0-20210903071746-97244b99971b
2 changes: 1 addition & 1 deletion memexec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func open(b []byte) (*os.File, error) {
if err != nil {
return nil, err
}
f := os.NewFile(uintptr(fd), fmt.Sprintf("/proc/self/fd/%d", fd))
f := os.NewFile(uintptr(fd), fmt.Sprintf("/proc/%d/fd/%d", os.Getpid(), fd))
if _, err := f.Write(b); err != nil {
_ = f.Close()
return nil, err
Expand Down
23 changes: 22 additions & 1 deletion memexec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package memexec

import (
"bytes"
"context"
"os"
"os/exec"
Expand All @@ -24,6 +25,26 @@ func TestCommand(t *testing.T) {
}
}

func TestCommand_Shell(t *testing.T) {
if runtime.GOOS == "windows" {
return
}

exe, err := New([]byte("#!/bin/sh\necho hello"))
if err != nil {
panic(err)
}
defer exe.Close()

b, err := exe.Command().CombinedOutput()
if err != nil {
t.Fatalf("err = %v, output = %q", err, b)
}
if !bytes.Equal(b, []byte("hello\n")) {
t.Fatalf("output = %q, want %q", string(b), []byte("hello\n"))
}
}

func TestCommandContext(t *testing.T) {
// the test is failing on windows, probably due to missing sleep command,
// unfortunately I have no windows machines around to fix this
Expand Down Expand Up @@ -104,7 +125,7 @@ func runCommand(t *testing.T, cmd *exec.Cmd) string {
b, err := cmd.CombinedOutput()
if err != nil {
if b != nil {
t.Fatal(string(b))
t.Fatalf("failed to run: %q", string(b))
}
t.Fatal(err)
}
Expand Down

0 comments on commit d27e26e

Please sign in to comment.