TestConfigCommandDocrootDetection asserts the default docroot is detected.
(t *testing.T)
| 494 | |
| 495 | // TestConfigCommandDocrootDetection asserts the default docroot is detected. |
| 496 | func TestConfigCommandDocrootDetection(t *testing.T) { |
| 497 | // Set up tests and give ourselves a working directory. |
| 498 | assert := asrt.New(t) |
| 499 | origDir, _ := os.Getwd() |
| 500 | |
| 501 | testMatrix := ddevapp.AvailablePHPDocrootLocations() |
| 502 | for index, testDocrootName := range testMatrix { |
| 503 | tmpDir := testcommon.CreateTmpDir(fmt.Sprintf("TestConfigCommand_%v", index)) |
| 504 | |
| 505 | // Create a document root folder. |
| 506 | err := os.MkdirAll(filepath.Join(tmpDir, filepath.Join(testDocrootName)), 0755) |
| 507 | if err != nil { |
| 508 | t.Errorf("Could not create %s directory under %s", testDocrootName, tmpDir) |
| 509 | } |
| 510 | _, err = os.OpenFile(filepath.Join(tmpDir, filepath.Join(testDocrootName), "index.php"), os.O_RDONLY|os.O_CREATE, 0664) |
| 511 | assert.NoError(err) |
| 512 | |
| 513 | // Create the ddevapp we'll use for testing. |
| 514 | // This will not return an error, since there is no existing configuration. |
| 515 | app, err := ddevapp.NewApp(tmpDir, true) |
| 516 | assert.NoError(err) |
| 517 | |
| 518 | t.Cleanup(func() { |
| 519 | err = os.Chdir(origDir) |
| 520 | assert.NoError(err) |
| 521 | err = app.Stop(true, false) |
| 522 | assert.NoError(err) |
| 523 | _ = os.RemoveAll(tmpDir) |
| 524 | }) |
| 525 | // Randomize some values to use for Stdin during testing. |
| 526 | name := strings.ToLower(util.RandString(16)) |
| 527 | |
| 528 | // Create an example input buffer that writes the site name, accepts the |
| 529 | // default document root and provides a valid app type. |
| 530 | input := fmt.Sprintf("%s\n\ndrupal8", name) |
| 531 | scanner := bufio.NewScanner(strings.NewReader(input)) |
| 532 | util.SetInputScanner(scanner) |
| 533 | |
| 534 | restoreOutput := util.CaptureStdOut() |
| 535 | err = app.PromptForConfig() |
| 536 | assert.NoError(err, t) |
| 537 | out := restoreOutput() |
| 538 | |
| 539 | assert.Contains(out, fmt.Sprintf("Docroot Location (%s)", testDocrootName)) |
| 540 | |
| 541 | // Ensure values were properly set on the app struct. |
| 542 | assert.Equal(name, app.Name) |
| 543 | assert.Equal(nodeps.AppTypeDrupal8, app.Type) |
| 544 | assert.Equal(testDocrootName, app.Docroot) |
| 545 | err = ddevapp.PrepDdevDirectory(app) |
| 546 | assert.NoError(err) |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | // TestConfigCommandDocrootDetection asserts the default docroot is detected and has index.php. |
| 551 | // The `web` docroot check is before `docroot` this verifies the directory with an |
nothing calls this directly
no test coverage detected