github.com/oalders/ppath@v0.1.1/audit/config_test.go (about)

     1  package audit
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  	"runtime"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func init() {
    13  	_, filename, _, _ := runtime.Caller(0)
    14  	dir := path.Join(path.Dir(filename), "..")
    15  	if err := os.Chdir(dir); err != nil {
    16  		panic(err)
    17  	}
    18  }
    19  
    20  func TestPpathConfigDoesNotExist(t *testing.T) {
    21  	c, err := PpathConfig("testdata/.noppath.toml")
    22  	assert.NoError(t, err)
    23  
    24  	var empty []string
    25  	assert.Equal(t, empty, c.Ignore)
    26  	assert.Equal(
    27  		t,
    28  		empty,
    29  		c.Commands["omegasort-gitignore"].Ignore,
    30  	)
    31  }
    32  
    33  func TestPpathConfig(t *testing.T) {
    34  	c, err := PpathConfig("testdata/.ppath.toml")
    35  	assert.NoError(t, err)
    36  
    37  	assert.Equal(t, []string{`**/node_modules/**/*`}, c.Ignore)
    38  	assert.Equal(
    39  		t,
    40  		[]string{`**/foo/**/*`},
    41  		c.Commands["omegasort-gitignore"].Ignore,
    42  	)
    43  }
    44  
    45  func TestPreciousConfigDoesNotExist(t *testing.T) {
    46  	c, err := PreciousConfig("testdata/precious-not-found.toml")
    47  	assert.Error(t, err)
    48  	assert.Empty(t, c)
    49  }
    50  
    51  func TestPreciousFailConfig(t *testing.T) {
    52  	c, err := PreciousConfig("testdata/precious-fail.toml")
    53  	assert.NoError(t, err)
    54  
    55  	assert.Equal(t,
    56  		Command{
    57  			Exclude: "baz",
    58  			Include: `**/.gitignore`,
    59  		},
    60  		c.Commands["omegasort-gitignore"],
    61  	)
    62  
    63  	assert.Equal(t,
    64  		Command{
    65  			Exclude: []interface{}{"foo", "bar"},
    66  			Include: []interface{}{`**/*.go`},
    67  		},
    68  		c.Commands["golangci-lint"],
    69  	)
    70  }
    71  
    72  func TestPreciousSuccessConfig(t *testing.T) {
    73  	c, err := PreciousConfig("testdata/precious.toml")
    74  	assert.NoError(t, err)
    75  
    76  	assert.Equal(t,
    77  		Command{
    78  			Exclude: nil,
    79  			Include: `**/.gitignore`,
    80  		},
    81  		c.Commands["omegasort-gitignore"],
    82  	)
    83  
    84  	assert.Equal(t,
    85  		Command{
    86  			Exclude: nil,
    87  			Include: []interface{}{`**/*.go`},
    88  		},
    89  		c.Commands["golangci-lint"],
    90  	)
    91  }