github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/step/step_split_monorepo_test.go (about) 1 // +build unit 2 3 package step_test 4 5 import ( 6 "io/ioutil" 7 "os" 8 "path/filepath" 9 "testing" 10 11 step2 "github.com/olli-ai/jx/v2/pkg/cmd/opts/step" 12 13 "github.com/olli-ai/jx/v2/pkg/cmd/step" 14 15 "github.com/olli-ai/jx/v2/pkg/cmd/opts" 16 "github.com/olli-ai/jx/v2/pkg/tests" 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestStepSplitMonorepo(t *testing.T) { 21 t.Parallel() 22 testData := filepath.Join("test_data", "split_monorepo") 23 24 tempDir, err := ioutil.TempDir("", "test_split_monorepo") 25 assert.NoError(t, err) 26 defer func() { 27 _ = os.RemoveAll(tempDir) 28 }() 29 30 options := &step.StepSplitMonorepoOptions{ 31 StepOptions: step2.StepOptions{ 32 CommonOptions: &opts.CommonOptions{}, 33 }, 34 Organisation: "dummy", 35 Glob: "*", 36 Dir: testData, 37 OutputDir: tempDir, 38 NoGit: true, 39 } 40 41 err = options.Run() 42 assert.NoError(t, err, "Failed to run split monorepo on source %s output %s", testData, tempDir) 43 44 tests.AssertDirsExist(t, true, filepath.Join(tempDir, "bar"), filepath.Join(tempDir, "foo")) 45 tests.AssertDirsExist(t, false, filepath.Join(tempDir, "kubernetes")) 46 47 tests.AssertFilesExist(t, true, 48 filepath.Join(tempDir, "bar", "charts", "bar", "Chart.yaml"), 49 filepath.Join(tempDir, "bar", "charts", "bar", "templates", "deployment.yaml")) 50 } 51 52 func TestStepSplitMonorepoGetLastGitCommit(t *testing.T) { 53 t.Parallel() 54 testData := filepath.Join("test_data", "split_monorepo") 55 56 tempDir, err := ioutil.TempDir("", "test_split_monorepo") 57 assert.NoError(t, err) 58 defer func() { 59 _ = os.RemoveAll(tempDir) 60 }() 61 62 options := &step.StepSplitMonorepoOptions{ 63 StepOptions: step2.StepOptions{ 64 CommonOptions: &opts.CommonOptions{}, 65 }, 66 Organisation: "dummy", 67 Glob: "*", 68 Dir: testData, 69 OutputDir: tempDir, 70 RepoName: "test", 71 NoGit: true, 72 } 73 74 err = options.Run() 75 assert.NoError(t, err, "Failed to run split monorepo on source %s output %s", testData, tempDir) 76 77 tests.AssertDirsExist(t, true, filepath.Join(tempDir, "bar"), filepath.Join(tempDir, "foo")) 78 tests.AssertDirsExist(t, false, filepath.Join(tempDir, "kubernetes")) 79 80 tests.AssertFilesExist(t, true, 81 filepath.Join(tempDir, "bar", "charts", "bar", "Chart.yaml"), 82 filepath.Join(tempDir, "bar", "charts", "bar", "templates", "deployment.yaml")) 83 }