github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/pkg/common/pwd_test.go (about)

     1  package common
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestPWD(t *testing.T) {
    12  	tcs := []struct {
    13  		name string
    14  		path string
    15  	}{
    16  		{
    17  			"original dir",
    18  			"",
    19  		},
    20  		{
    21  			"subdirectory",
    22  			"subdir",
    23  		},
    24  	}
    25  	for _, tc := range tcs {
    26  		t.Run(tc.name, func(t *testing.T) {
    27  			assert := assert.New(t)
    28  			wd, _ := os.Getwd()
    29  			os.Chdir(filepath.Join("testdata/cat/", tc.path))
    30  
    31  			p := PWD{}
    32  			output, err := p.Run("", "", []string{})
    33  			assert.NoError(err)
    34  			assert.Contains(output, filepath.Join("testdata/cat/", tc.path))
    35  			os.Chdir(wd)
    36  		})
    37  	}
    38  }