github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/pkg/project/changeset_test.go (about)

     1  package project_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/tooploox/oya/pkg/oyafile"
     9  	"github.com/tooploox/oya/pkg/project"
    10  	tu "github.com/tooploox/oya/testutil"
    11  )
    12  
    13  func TestProject_Changeset(t *testing.T) {
    14  	testCases := []struct {
    15  		desc       string
    16  		projectDir string
    17  		workDir    string
    18  		expected   []*oyafile.Oyafile
    19  	}{
    20  		{
    21  			desc:       "Default changeset",
    22  			projectDir: "./fixtures/project",
    23  			workDir:    "./fixtures/project",
    24  			expected:   tu.MustListOyafiles(t, "./fixtures/project"),
    25  		},
    26  		{
    27  			desc:       "Default changeset from subdir",
    28  			projectDir: "./fixtures/project",
    29  			workDir:    "./fixtures/project/subdir/",
    30  			expected:   tu.MustListOyafilesSubdir(t, "./fixtures/project", "./fixtures/project/subdir"),
    31  		},
    32  	}
    33  
    34  	installDir, err := ioutil.TempDir("", "oya")
    35  	tu.AssertNoErr(t, err, "Error creating temp dir")
    36  	defer os.RemoveAll(installDir)
    37  
    38  	for _, tc := range testCases {
    39  		p, err := project.Detect(tc.projectDir, installDir)
    40  		tu.AssertNoErr(t, err, "Expected no error trying to detect Oya project in %v (test case %q)", tc.projectDir, tc.desc)
    41  
    42  		actual, err := p.Changeset(tc.workDir)
    43  		tu.AssertNoErr(t, err, "Error calculating changeset (test case %q)", tc.desc)
    44  		tu.AssertObjectsEqualMsg(t, tc.expected, actual, "Unexpected changeset (test case %q)", tc.desc)
    45  	}
    46  }