github.com/Odesyuk/pop@v4.13.1+incompatible/fix/anko_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"io/ioutil"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/gobuffalo/packr/v2"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_Anko(t *testing.T) {
    13  	r := require.New(t)
    14  	box := packr.New("./fixtures/anko", "./fixtures/anko")
    15  	err := box.Walk(func(path string, info packr.File) error {
    16  		if strings.HasPrefix(path, "pass") {
    17  			t.Run(path, testPass(path, info))
    18  			return nil
    19  		}
    20  		t.Run(path, testFail(path, info))
    21  		return nil
    22  	})
    23  	r.NoError(err)
    24  }
    25  
    26  func testPass(path string, info packr.File) func(*testing.T) {
    27  	return func(t *testing.T) {
    28  		r := require.New(t)
    29  		b, err := ioutil.ReadAll(info)
    30  		r.NoError(err)
    31  
    32  		body := string(b)
    33  		fixed, err := Anko(body)
    34  		r.NoError(err)
    35  		if strings.Contains(path, "anko") {
    36  			r.NotEqual(body, fixed)
    37  		} else {
    38  			r.Equal(body, fixed)
    39  		}
    40  	}
    41  }
    42  
    43  func testFail(path string, info packr.File) func(*testing.T) {
    44  	return func(t *testing.T) {
    45  		r := require.New(t)
    46  		b, err := ioutil.ReadAll(info)
    47  		r.NoError(err)
    48  
    49  		body := string(b)
    50  		_, err = Anko(body)
    51  		r.Error(err)
    52  	}
    53  }