github.com/monomonedula/gopdd@v1.2.1/pkg/gopdd/collector_test.go (about)

     1  package gopdd
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestCollectPuzzlesOk(t *testing.T) {
    12  	origindir, err := os.Getwd()
    13  	if err != nil {
    14  		panic(err)
    15  	}
    16  	defer os.Chdir(origindir)
    17  	err = os.Chdir("../..")
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  	path := "resources/foobar.py"
    22  	content, err := os.ReadFile(path)
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  	puzzles, err := Source{file: path, source: string(content)}.CollectPuzzles(false)
    27  	assert.Equal(t, nil, err)
    28  	assert.Equal(t, len(puzzles), 2, "Must find two puzzles")
    29  	assert.Equal(
    30  		t,
    31  		Puzzle{
    32  			Id:       "209-c992021",
    33  			Ticket:   "209",
    34  			Estimate: 30,
    35  			Role:     "DEV",
    36  			Lines:    "3-5",
    37  			Body:     "whatever 1234. Please fix soon 1.",
    38  			File:     "resources/foobar.py",
    39  			Author:   "monomonedula",
    40  			Email:    "valh@tuta.io",
    41  			Time:     "2023-03-26T23:27:31+03:00",
    42  		},
    43  		puzzles[0],
    44  	)
    45  	assert.Equal(
    46  		t,
    47  		Puzzle{
    48  			Id:       "321-b7bbd66",
    49  			Ticket:   "321",
    50  			Estimate: 60,
    51  			Role:     "DEV",
    52  			Lines:    "9-11",
    53  			Body:     "very important issue. Please fix soon 2.",
    54  			File:     "resources/foobar.py",
    55  			Author:   "monomonedula",
    56  			Email:    "valh@tuta.io",
    57  			Time:     "2023-03-26T23:27:31+03:00",
    58  		},
    59  		puzzles[1],
    60  	)
    61  }
    62  
    63  func TestCollectSourcesOk(t *testing.T) {
    64  	origindir, err := os.Getwd()
    65  	if err != nil {
    66  		panic(err)
    67  	}
    68  	defer os.Chdir(origindir)
    69  	err = os.Chdir("../..")
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  	sources, err := MakeSources(
    74  		".",
    75  		[]string{
    76  			"*/must_be_excluded.py",
    77  			"*.txt",
    78  			"pkg/*",
    79  			"go.mod",
    80  			"go.sum",
    81  			"cmd/*",
    82  		},
    83  		[]string{},
    84  		true,
    85  	)
    86  	assert.Equal(t, nil, err)
    87  	found := sources.fetch()
    88  	assert.Equal(t, 1, len(found))
    89  	cwd, _ := os.Getwd()
    90  	assert.Equal(t, path.Join(cwd, "resources/foobar.py"), found[0].file)
    91  }