github.com/t-ham752/go-linux@v0.0.0-20230521064409-70f30d2872cc/pkg/cat/cat_test.go (about)

     1  package cat
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestRun(t *testing.T) {
     9  	tests := []struct {
    10  		name string
    11  		args []string
    12  		want string
    13  	}{
    14  		{
    15  			name: "one arg",
    16  			args: []string{"cmd", "testdata/sample1.txt"},
    17  			want: "okane",
    18  		},
    19  		{
    20  			name: "two args",
    21  			args: []string{"cmd", "testdata/sample1.txt", "testdata/sample2.txt"},
    22  			want: "okanehoshii",
    23  		},
    24  	}
    25  	for _, tt := range tests {
    26  		t.Run(tt.name, func(t *testing.T) {
    27  			stdout := bytes.Buffer{}
    28  			err := run(tt.args, &stdout)
    29  			if err != nil {
    30  				t.Errorf("run() error = %v", err)
    31  			}
    32  			if got := stdout.String(); got != tt.want {
    33  				t.Errorf("run() = %v, want %v", got, tt.want)
    34  			}
    35  		})
    36  	}
    37  }