github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/standard/tester_test.go (about)

     1  package standard
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestRunBeforeTest(t *testing.T) {
    11  	p := &Tester{}
    12  	ctx := context.Background()
    13  	err := p.RunBeforeTest(ctx, "", []string{})
    14  
    15  	if err != nil {
    16  		t.Errorf("Should not error, got %v", err)
    17  	}
    18  
    19  	env := os.Getenv("GO_ENV")
    20  	if env != "test" {
    21  		t.Errorf("GO_ENV should is %v should be %v", env, "test")
    22  	}
    23  }
    24  
    25  func TestCommandArgs(t *testing.T) {
    26  	p := &Tester{}
    27  
    28  	tcases := []struct {
    29  		args     []string
    30  		expected string
    31  		name     string
    32  	}{
    33  		{
    34  			args:     []string{"-p", "3"},
    35  			expected: "test -p 3",
    36  			name:     "P present",
    37  		},
    38  
    39  		{
    40  			args:     []string{},
    41  			expected: "test -p 1 ./...",
    42  			name:     "blank",
    43  		},
    44  
    45  		{
    46  			args:     []string{"./app/actions/..."},
    47  			expected: "test -p 1 ./app/actions/...",
    48  			name:     "only route",
    49  		},
    50  	}
    51  
    52  	for _, tcase := range tcases {
    53  		t.Run(tcase.name, func(t *testing.T) {
    54  			targs := p.testArgs(tcase.args)
    55  			actual := strings.Join(targs, " ")
    56  			if actual != tcase.expected {
    57  				t.Errorf("should have gotten %v and got %v", tcase.expected, actual)
    58  			}
    59  		})
    60  	}
    61  }