Skip to content

Commit

Permalink
Move underscores test first, so that no config exists yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbomb007 committed May 22, 2024
1 parent 40fe015 commit 71ec9f3
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions pkg/ddevapp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,39 @@ func TestConfigCommand(t *testing.T) {
name := strings.ToLower(util.RandString(16))
invalidAppType := strings.ToLower(util.RandString(8))

// Create a docroot folder containing underscores.
err = os.Mkdir(filepath.Join(testDir, "docroot_with_underscores"), 0644)
if err != nil {
t.Errorf("Could not create docroot_with_underscores directory under %s", testDir)
}

// Create an example input buffer that uses the default projectname , then a
// valid document root, then a valid app type.
input = fmt.Sprintf("\n\ndocroot_with_underscores\n%s", testValues[apptypePos])

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: input

Check failure on line 268 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: input
scanner = bufio.NewScanner(strings.NewReader(input))

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: input

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: scanner

Check failure on line 269 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: input
util.SetInputScanner(scanner)

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: scanner

Check failure on line 270 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: scanner

restoreOutput = util.CaptureUserOut()

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: restoreOutput

Check failure on line 272 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: restoreOutput
err = app.PromptForConfig()
assert.NoError(err)
out = restoreOutput()

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: restoreOutput

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: out

Check failure on line 275 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: restoreOutput

// Ensure we have expected vales in output.
assert.Contains(out, testDir)

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: out

Check failure on line 278 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: out
assert.NotContains(out, "docroot_with_underscores is not a valid project name")

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

undefined: out

Check failure on line 279 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

undefined: out

// Ensure values were properly set on the app struct.
assert.Equal("docroot-with-underscores", app.Name)
assert.Equal(testValues[apptypePos], app.Type)
assert.Equal("docroot_with_underscores", app.Docroot)
assert.EqualValues(testValues[phpVersionPos], app.PHPVersion, "PHP value incorrect for apptype %v (expected %s got %s) (%v)", app.Type, testValues[phpVersionPos], app.PHPVersion, app)
err = ddevapp.PrepDdevDirectory(app)
assert.NoError(err)

// Randomize some values to use for Stdin during testing.
name := strings.ToLower(util.RandString(16))

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / Lint Go Files

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (pull-push-test-platforms, true)

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (mutagen, true)

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-fpm, nginx-fpm)

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (apache-fpm, apache-fpm)

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (race-detection, true)

no new variables on left side of :=

Check failure on line 290 in pkg/ddevapp/config_test.go

View workflow job for this annotation

GitHub Actions / tests (nginx-proxy, nginx-proxy)

no new variables on left side of :=
invalidAppType := strings.ToLower(util.RandString(8))

// Create an example input buffer that writes the sitename, a valid document root,
// an invalid app type, and finally a valid app type (from test matrix)
input := fmt.Sprintf("%s\ndocroot\n%s\n%s", name, invalidAppType, testValues[apptypePos])
Expand Down Expand Up @@ -294,35 +327,6 @@ func TestConfigCommand(t *testing.T) {
assert.EqualValues(testValues[phpVersionPos], app.PHPVersion, "PHP value incorrect for apptype %v (expected %s got %s) (%v)", app.Type, testValues[phpVersionPos], app.PHPVersion, app)
err = ddevapp.PrepDdevDirectory(app)
assert.NoError(err)

// Create a docroot folder containing underscores.
err = os.Mkdir(filepath.Join(testDir, "docroot_with_underscores"), 0644)
if err != nil {
t.Errorf("Could not create docroot_with_underscores directory under %s", testDir)
}

// Create an example input buffer that uses the default projectname, then a
// valid document root, then a valid app type.
input = fmt.Sprintf("\n\ndocroot_with_underscores\n%s", testValues[apptypePos])
scanner = bufio.NewScanner(strings.NewReader(input))
util.SetInputScanner(scanner)

restoreOutput = util.CaptureUserOut()
err = app.PromptForConfig()
assert.NoError(err)
out = restoreOutput()

// Ensure we have expected vales in output.
assert.Contains(out, testDir)
assert.NotContains(out, "docroot_with_underscores is not a valid project name")

// Ensure values were properly set on the app struct.
assert.Equal("docroot-with-underscores", app.Name)
assert.Equal(testValues[apptypePos], app.Type)
assert.Equal("docroot_with_underscores", app.Docroot)
assert.EqualValues(testValues[phpVersionPos], app.PHPVersion, "PHP value incorrect for apptype %v (expected %s got %s) (%v)", app.Type, testValues[phpVersionPos], app.PHPVersion, app)
err = ddevapp.PrepDdevDirectory(app)
assert.NoError(err)
}
}

Expand Down

0 comments on commit 71ec9f3

Please sign in to comment.