Skip to content

Commit

Permalink
integration: split tests into nonmem and postrun subdirectories
Browse files Browse the repository at this point in the history
A subset of the integration tests don't require NONMEM.  It's
convenient to have them in a separate package from the ones that do so
that they can be more easily executed on machines that don't have
NONMEM.
  • Loading branch information
kyleam committed Aug 9, 2024
1 parent 835953e commit 56b3430
Show file tree
Hide file tree
Showing 201 changed files with 60 additions and 49 deletions.
6 changes: 3 additions & 3 deletions integration/execute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package integration

import (
"context"
Expand All @@ -10,7 +10,7 @@ import (
log "github.com/sirupsen/logrus"
)

func executeCommand(ctx context.Context, command string, args ...string) (string, error) {
func ExecuteCommand(ctx context.Context, command string, args ...string) (string, error) {
//Find it in path
binary, _ := exec.LookPath(command)
cmd := exec.CommandContext(ctx, binary, args...)
Expand Down Expand Up @@ -40,7 +40,7 @@ func executeCommand(ctx context.Context, command string, args ...string) (string
}

// nolint:unparam
func executeCommandNoErrorCheck(ctx context.Context, command string, args ...string) (string, error) {
func ExecuteCommandNoErrorCheck(ctx context.Context, command string, args ...string) (string, error) {
binary, _ := exec.LookPath(command)
cmd := exec.CommandContext(ctx, binary, args...)
cmd.Env = os.Environ()
Expand Down
1 change: 1 addition & 0 deletions integration/nonmem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains integration tests that rely on having NONMEM installed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (
"strings"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestBBIExpandsWithoutPrefix(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestBBIExpandsWithPrefix(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestBBIExpandsWithPrefixToPartialMatch(tt *testing.T) {
filepath.Join(scenario.Workpath, "model", targets),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (
"testing"
"time"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestNMFEOptionsEndInScript(tt *testing.T) {

// Now let's run the script that was generated
t.R.NoError(os.Chdir(filepath.Join(scenario.Workpath, m.identifier)))
_, err = executeCommand(ctx, filepath.Join(scenario.Workpath, m.identifier, m.identifier+".sh"))
_, err = ExecuteCommand(ctx, filepath.Join(scenario.Workpath, m.identifier, m.identifier+".sh"))
t.R.NoError(os.Chdir(whereami))
t.R.NoError(err)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion integration/files.go → integration/nonmem/files.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"io/ioutil"
Expand Down
5 changes: 3 additions & 2 deletions integration/init_test.go → integration/nonmem/init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand All @@ -10,6 +10,7 @@ import (
"runtime"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand All @@ -34,7 +35,7 @@ func TestInitialization(tt *testing.T) {
scenario.Prepare(t, context.Background())

t.Run(fmt.Sprintf("init_%s", scenario.identifier), func(t *wrapt.T) {
_, err := executeCommand(context.Background(), "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
_, err := ExecuteCommand(context.Background(), "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
t.R.NoError(err)

t.A.FileExists(filepath.Join(scenario.Workpath, "bbi.yaml"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion integration/nonmem.go → integration/nonmem/nonmem.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"crypto/md5"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"bufio"
Expand Down
17 changes: 6 additions & 11 deletions integration/setup.go → integration/nonmem/setup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package nonmem

import (
"archive/tar"
Expand All @@ -14,6 +14,8 @@ import (
"strconv"
"strings"

. "github.com/metrumresearchgroup/bbi/integration"

"github.com/metrumresearchgroup/wrapt"
log "github.com/sirupsen/logrus"
"github.com/spf13/afero"
Expand All @@ -23,13 +25,6 @@ import (
var ROOT_EXECUTION_DIR string
var EXECUTION_DIR string

// constants and variables used in summary tests.
const SUMMARY_TEST_DIR = "testdata/bbi_summary"
const SUMMARY_GOLD_DIR = "aa_golden_files"
const noSuchFileError = "no such file or directory"
const noFilePresentError = "no file present at"
const wrongExtensionError = "Must provide path to .lst"

type Scenario struct {
Details ScenarioDetails
ctx context.Context
Expand Down Expand Up @@ -67,7 +62,7 @@ func (m Model) Execute(scenario *Scenario, args ...string) (string, error) {
filepath.Join(scenario.Workpath, m.filename),
}...)

return executeCommand(scenario.ctx, "bbi", cmdArguments...)
return ExecuteCommand(scenario.ctx, "bbi", cmdArguments...)
}

var ErrNoModelsLocated = errors.New("no model directories were located in the provided scenario")
Expand Down Expand Up @@ -437,7 +432,7 @@ func findModelFiles(path string) []string {
func (scenario *Scenario) Prepare(t *wrapt.T, ctx context.Context) {
t.Helper()

_, err := executeCommand(ctx, "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
_, err := ExecuteCommand(ctx, "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
t.R.NoError(err)

fs := afero.NewOsFs()
Expand All @@ -457,7 +452,7 @@ func (scenario *Scenario) Prepare(t *wrapt.T, ctx context.Context) {

t.R.NoError(os.Chdir(scenario.Workpath))

_, err = executeCommand(ctx, "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
_, err = ExecuteCommand(ctx, "bbi", "init", "--dir", os.Getenv("NONMEMROOT"))
t.R.NoError(err)

t.R.NoError(os.Chdir(whereami))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions integration/README.md → integration/postrun/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# bbitest
This directory contains integration tests data. Many of these tests must be run in an environment containing a working NONMEM installation and/or worker nodes that can be used to execute jobs. See [`.drone.yml`](/.drone.yml) for examples.
This directory contains integration tests that do _not_ rely on having
NONMEM installed.

## Refreshing golden files
The `bbi nonmem summary` tests (in `integration/bbi_summary_test.go`) use golden files stored in `integration/testdata/bbi_summary/aa_golden_files/`. These need to be refreshed when the relevant functionality in `bbi` changes. This can be done by running the tests with the `UPDATE_SUMMARY=true` environment variable, like so:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package postrun

import (
"context"
Expand All @@ -7,6 +7,7 @@ import (
"regexp"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand All @@ -32,7 +33,7 @@ func TestCovCorHappyPath(tt *testing.T) {
filepath.Join(SUMMARY_TEST_DIR, mod.name, mod.name),
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestCovCorErrors(tt *testing.T) {

// try without flag and get error
var output string
output, err := executeCommandNoErrorCheck(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommandNoErrorCheck(context.Background(), "bbi", commandAndArgs...)
t.R.Error(err)

errorMatch := rgx.MatchString(output)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bbitest
package postrun

import (
"context"
"os"
"path/filepath"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"
"github.com/metrumresearchgroup/wrapt"
)
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestParamsSingleModel(tt *testing.T) {
commandAndArgs = append(commandAndArgs, tc.bbiOption)
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestParamsDir(tt *testing.T) {
commandAndArgs = append(commandAndArgs, tc.bbiOption)
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package postrun

import (
"context"
Expand All @@ -7,6 +7,7 @@ import (
"regexp"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/wrapt"
)

Expand All @@ -22,7 +23,7 @@ func TestBBIRecleanBasic(tt *testing.T) {
_ = ioutil.WriteFile(fdataCSV, []byte("fake"), 0644)
t.A.FileExists(fdataCSV)

output, err := executeCommand(context.Background(),
output, err := ExecuteCommand(context.Background(),
"bbi", "nonmem", "reclean", "--recleanLvl=1", "-v", dir)
t.R.NoError(err)
t.R.NotEmpty(output)
Expand All @@ -33,7 +34,7 @@ func TestBBIRecleanBasic(tt *testing.T) {
func TestBBIRecleanError(tt *testing.T) {
t := wrapt.WrapT(tt)

output, err := executeCommandNoErrorCheck(context.Background(),
output, err := ExecuteCommandNoErrorCheck(context.Background(),
"bbi", "nonmem", "reclean")

t.R.NotNil(err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package postrun

import (
"context"
Expand All @@ -7,6 +7,7 @@ import (
"regexp"
"testing"

. "github.com/metrumresearchgroup/bbi/integration"
"github.com/metrumresearchgroup/bbi/utils"

"github.com/metrumresearchgroup/wrapt"
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestSummaryHappyPath(tt *testing.T) {
commandAndArgs = append(commandAndArgs, tc.bbiOption)
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -130,14 +131,14 @@ func TestSummaryArgs(tt *testing.T) {
}

// try without flag and get error
output, err := executeCommandNoErrorCheck(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommandNoErrorCheck(context.Background(), "bbi", commandAndArgs...)
t.R.NotNil(err)
errorMatch, _ := regexp.MatchString(tm.errorRegEx, output)
t.R.True(errorMatch)

// append flag and get success
commandAndArgs = append(commandAndArgs, tm.bbiArg)
output, err = executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err = ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -216,7 +217,7 @@ func TestSummaryErrors(tt *testing.T) {
args = append(args, tc.bbiArgs...)
}
args = append(args, filepath.Join(SUMMARY_TEST_DIR, tc.testPath))
output, err := executeCommandNoErrorCheck(context.Background(), "bbi", args...)
output, err := ExecuteCommandNoErrorCheck(context.Background(), "bbi", args...)
t.R.NotNil(err)
errorMatch, _ := regexp.MatchString(tc.errorMsg, output)
t.R.True(errorMatch)
Expand All @@ -237,7 +238,7 @@ func TestSummaryHappyPathNoExtension(tt *testing.T) {
filepath.Join(SUMMARY_TEST_DIR, mod, mod), // adding no extension should work
}

output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

t.R.NoError(err)
t.R.NotEmpty(output)
Expand Down Expand Up @@ -268,7 +269,7 @@ func TestSummaryHappyPathMultipleModels(tt *testing.T) {
if tc.bbiOption != "" {
commandAndArgs = append(commandAndArgs, tc.bbiOption)
}
output, err := executeCommand(context.Background(), "bbi", commandAndArgs...)
output, err := ExecuteCommand(context.Background(), "bbi", commandAndArgs...)

gtd := GoldenFileTestingDetails{
outputString: output,
Expand Down Expand Up @@ -306,7 +307,7 @@ func TestSummaryPathMultipleModelsError(tt *testing.T) {
if tc.bbiOption != "" {
commandAndArgs = append(commandAndArgs, tc.bbiOption)
}
output, err := executeCommandNoErrorCheck(context.Background(),
output, err := ExecuteCommandNoErrorCheck(context.Background(),
"bbi", commandAndArgs...)

// Avoid testing plain output with golden file due to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bbitest
package postrun

import (
"fmt"
Expand Down
Loading

0 comments on commit 56b3430

Please sign in to comment.