-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
174 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Go Lint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
golangci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run Golangci-lint | ||
uses: golangci/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package binarymanagers | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
) | ||
|
||
type PipedOutput struct { | ||
Handle *exec.Cmd | ||
Stdout io.ReadCloser | ||
Stderr io.ReadCloser | ||
} | ||
|
||
func RunPiped(cmd string, pipedInput io.Reader) (PipedOutput, error) { | ||
|
||
fullCmd := exec.Command("sh", "-c", cmd) | ||
|
||
stdout, err := fullCmd.StdoutPipe() | ||
if err != nil { | ||
return PipedOutput{}, fmt.Errorf("failed getting stdout: %v", err) | ||
} | ||
|
||
stderr, err := fullCmd.StderrPipe() | ||
if err != nil { | ||
return PipedOutput{}, fmt.Errorf("failed getting stderr: %v", err) | ||
} | ||
|
||
if pipedInput != nil { | ||
fullCmd.Stdin = pipedInput | ||
} | ||
|
||
if err := fullCmd.Start(); err != nil { | ||
return PipedOutput{}, fmt.Errorf("command failed: %v", err) | ||
} | ||
|
||
return PipedOutput{Handle: fullCmd, Stdout: stdout, Stderr: stderr}, nil | ||
} | ||
|
||
func Run(cmd string) (string, error) { | ||
|
||
fullCmd := exec.Command("sh", "-c", cmd) | ||
|
||
outputBytes, err := fullCmd.CombinedOutput() | ||
if err != nil { | ||
return "", fmt.Errorf("command failed: %v", err) | ||
} | ||
return string(outputBytes), nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package binarymanagers | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
output, err := Run("echo hello") | ||
require.NoError(t, err) | ||
require.Equal(t, "hello\n", output) | ||
} | ||
|
||
func FuzzRunPiped(f *testing.F) { | ||
// Test echo to cat | ||
f.Fuzz(func(t *testing.T, message string) { | ||
echoCmd, err := RunPiped("echo "+message, nil) | ||
require.NoError(t, err) | ||
|
||
catCmd, err := RunPiped("cat", echoCmd.Stdout) | ||
require.NoError(t, err) | ||
|
||
catCmd2, err := RunPiped("cat", catCmd.Stdout) | ||
require.NoError(t, err) | ||
|
||
// Properly read from the result.Stdout before calling Wait | ||
var out bytes.Buffer | ||
_, err = io.Copy(&out, catCmd2.Stdout) | ||
require.NoError(t, err) | ||
|
||
// We only need to wait on the last command | ||
require.NoError(t, catCmd2.Handle.Wait()) | ||
|
||
// Assert the final output | ||
require.Equal(t, message+"\n", out.String()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
type FfmpegClient struct { | ||
binary string | ||
} | ||
|
||
func NewFFmpegClient() (*FfmpegClient, error) { | ||
|
||
// look for ffmpeg in path | ||
if _, err := os.Stat("ffmpeg"); os.IsNotExist(err) { | ||
return &FfmpegClient{binary: "ffmpeg"}, nil | ||
} else { | ||
return &FfmpegClient{}, fmt.Errorf("ffmpeg binary not found: %v", err) | ||
} | ||
|
||
} | ||
|
||
func (c *FfmpegClient) Run(cmd String) error { | ||
// construct the command | ||
cmdList := fmt.Sprintf("%s %s", c.binary, cmd) | ||
|
||
// run the command | ||
fullCmd := exec.Command("sh", "-c", cmdList) | ||
output, err := fullCmd.StdoutPipe() | ||
|
||
if err != nil { | ||
return fmt.Errorf("ffmpeg command failed: %v\n%s", err, string(output)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewFFmpegClient(t *testing.T) { | ||
client, err := NewFFmpegClient() | ||
require.NotNil(t, client) | ||
require.NoError(t, err) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.