Skip to content

Commit

Permalink
test: add stdout stderr stream checks
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Dec 23, 2024
1 parent 20d002a commit 2f95714
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/integration.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ exec chmod +x bin/example-app
exec ls -la bin/example-app
exec bin/example-app coin

exec harpoon capture -f main.main -- ./bin/example-app coin
stdout 'write'

exec harpoon capture -f main.main -c -- ./bin/example-app coin
stdout 'stdout: \[flip coin\]'

exec harpoon capture -f main.main -e -- ./bin/example-app streams
stdout 'stderr: 0'

exec harpoon capture -f main.main -c -e -- ./bin/example-app streams
stdout 'stdout: 0'
stdout 'stderr: 0'

exec harpoon capture -f main.main -- ./bin/example-app coin
stdout 'write'

Expand Down
39 changes: 39 additions & 0 deletions tests/testcases/example-app/cmd/streams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"

"github.com/alegrey91/seccomp-test-coverage/pkg/streams"
)

// streamsCmd represents the streams command
var streamsCmd = &cobra.Command{
Use: "streams",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
streams.PrintOutErr()
},
}

func init() {
rootCmd.AddCommand(streamsCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// streamsCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// streamsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
13 changes: 13 additions & 0 deletions tests/testcases/example-app/pkg/streams/streams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package streams

import (
"fmt"
"os"
)

func PrintOutErr() {
for i := 0; i < 10; i++ {
fmt.Fprintf(os.Stderr, "%v\n", i)
fmt.Fprintf(os.Stdout, "%v\n", i)
}
}

0 comments on commit 2f95714

Please sign in to comment.