github.imxd.top/gopinath-langote/1build@v1.2.0/testing/fixtures/command_list_fixtures.go (about)

     1  package fixtures
     2  
     3  import (
     4  	"github.com/gopinath-langote/1build/testing/utils"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  )
     8  
     9  func FeatureListTestData() []Test {
    10  	var feature = "list"
    11  	return []Test{
    12  		shouldShowListOfCommands(feature),
    13  		shouldNotShowAnyCommandsIfNoCommandsFound(feature),
    14  		shouldShowCommandsWithBeforeAndAfterIfPresent(feature),
    15  	}
    16  }
    17  
    18  func shouldShowListOfCommands(feature string) Test {
    19  	commandListMessage := `--------------------------------------------------
    20  project: Sample Project
    21  commands:
    22  build | npm run build
    23  lint | eslint
    24  --------------------------------------------------
    25  `
    26  	defaultFileContent := `
    27  project: Sample Project
    28  commands:
    29    - build: npm run build
    30    - lint: eslint
    31  `
    32  
    33  	return Test{
    34  		Feature: feature,
    35  		Name:    "shouldShowListOfCommands",
    36  		CmdArgs: []string{"list"},
    37  		Setup: func(dir string) error {
    38  			return utils.CreateConfigFile(dir, defaultFileContent)
    39  		},
    40  		Assertion: func(dir string, actualOutput string, t *testing.T) bool {
    41  			return assert.Contains(t, actualOutput, commandListMessage)
    42  		},
    43  	}
    44  }
    45  
    46  func shouldNotShowAnyCommandsIfNoCommandsFound(feature string) Test {
    47  	emptyCommandListMessage := `--------------------------------------------------
    48  project: Sample Project
    49  commands:
    50  --------------------------------------------------
    51  `
    52  	return Test{
    53  		Feature: feature,
    54  		Name:    "shouldNotShowAnyCommandsIfNoCommandsFound",
    55  		CmdArgs: []string{},
    56  		Setup: func(dir string) error {
    57  			return utils.CreateConfigFile(dir, "project: Sample Project\ncommands:\n")
    58  		},
    59  		Assertion: func(dir string, actualOutput string, t *testing.T) bool {
    60  			return assert.Contains(t, actualOutput, emptyCommandListMessage)
    61  		},
    62  	}
    63  }
    64  
    65  func shouldShowCommandsWithBeforeAndAfterIfPresent(feature string) Test {
    66  	expectedOutput := `--------------------------------------------------
    67  project: Sample Project
    68  before: pre_command
    69  after: post_command
    70  commands:
    71  build | npm run build
    72  --------------------------------------------------
    73  `
    74  	fileContent := `
    75  project: Sample Project
    76  before: pre_command
    77  after: post_command
    78  commands:
    79    - build: npm run build
    80  `
    81  
    82  	return Test{
    83  		Feature: feature,
    84  		Name:    "shouldShowCommandsWithBeforeAndAfterIfPresent",
    85  		CmdArgs: []string{"list"},
    86  		Setup: func(dir string) error {
    87  			return utils.CreateConfigFile(dir, fileContent)
    88  		},
    89  		Assertion: func(dir string, actualOutput string, t *testing.T) bool {
    90  			return assert.Contains(t, actualOutput, expectedOutput)
    91  		},
    92  	}
    93  }