MCPcopy Index your code
hub / github.com/ddev/ddev / TestDdevImportFilesDir

Function TestDdevImportFilesDir

pkg/ddevapp/ddevapp_test.go:2687–2760  ·  view source on GitHub ↗

TestDdevImportFilesDir tests that "ddev import-files" can successfully import non-archive directories

(t *testing.T)

Source from the content-addressed store, hash-verified

2685
2686// TestDdevImportFilesDir tests that "ddev import-files" can successfully import non-archive directories
2687func TestDdevImportFilesDir(t *testing.T) {
2688 assert := asrt.New(t)
2689 origDir, _ := os.Getwd()
2690 app := &ddevapp.DdevApp{}
2691 var err error
2692
2693 // Create a dummy directory to test non-archive imports
2694 importDir := testcommon.CreateTmpDir(t.Name())
2695 fileNames := make([]string, 0)
2696 for range 5 {
2697 fileName := uuid.New().String()
2698 fileNames = append(fileNames, fileName)
2699
2700 fullPath := filepath.Join(importDir, fileName)
2701 err = os.WriteFile(fullPath, []byte(fileName), 0644)
2702 assert.NoError(err)
2703 }
2704
2705 for i, site := range TestSites {
2706 if site.Disable {
2707 t.Logf("Skipping TestSite %s=%d because disabled", site.Name, i)
2708 continue
2709 }
2710
2711 if site.FilesTarballURL == "" && site.FilesZipballURL == "" {
2712 t.Logf("== SKIP TestDdevImportFilesDir for %s (FilesTarballURL and FilesZipballURL are not provided)\n", site.Name)
2713 continue
2714 }
2715 runTime := util.TimeTrackC(fmt.Sprintf("%s %s", site.Name, t.Name()))
2716 t.Logf("== BEGIN TestDdevImportFilesDir for %s\n", site.Name)
2717
2718 testcommon.ClearDockerEnv()
2719 err = app.Init(site.Dir)
2720 if err != nil {
2721 assert.NoError(err, "failed app.Init for %s, continuing", site.Name)
2722 continue
2723 }
2724
2725 t.Cleanup(func() {
2726 err = os.Chdir(origDir)
2727 assert.NoError(err)
2728 err = app.Stop(true, false)
2729 assert.NoError(err)
2730 })
2731 err = os.Chdir(site.Dir)
2732 require.NoError(t, err)
2733
2734 // Function under test
2735 if app.GetUploadDir() == "" {
2736 continue
2737 }
2738 err = app.ImportFiles("", importDir, "")
2739 if err != nil {
2740 assert.NoError(err, "failed importing files directory %s for site %s: %v", importDir, site.Name, err)
2741 continue
2742 }
2743
2744 // Confirm contents of destination dir after import

Callers

nothing calls this directly

Calls 10

InitMethod · 0.95
StopMethod · 0.95
GetUploadDirMethod · 0.95
ImportFilesMethod · 0.95
CreateTmpDirFunction · 0.92
TimeTrackCFunction · 0.92
ClearDockerEnvFunction · 0.92
CleanupMethod · 0.80
ChdirMethod · 0.80

Tested by

no test coverage detected