github.com/getgauge/gauge@v1.6.9/cmd/list_test.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package cmd
     8  
     9  import (
    10  	"reflect"
    11  	"testing"
    12  
    13  	"github.com/getgauge/gauge-proto/go/gauge_messages"
    14  	"github.com/getgauge/gauge/gauge"
    15  	"github.com/getgauge/gauge/runner"
    16  )
    17  
    18  func TestOnlyUniqueTagsAreReturned(t *testing.T) {
    19  	listTags([]*gauge.Specification{buildTestSpecification()}, func(res []string) {
    20  		verifyUniqueness(res, []string{"bar", "foo"}, t)
    21  	})
    22  }
    23  
    24  func TestOnlyUniqueSpecsAreReturned(t *testing.T) {
    25  	specs := []*gauge.Specification{
    26  		buildTestSpecification(),
    27  		buildTestSpecification(),
    28  	}
    29  	listSpecifications(specs, func(res []string) {
    30  		verifyUniqueness(res, []string{"Spec1"}, t)
    31  	})
    32  }
    33  
    34  func TestOnlyUniqueSceanriosAreReturned(t *testing.T) {
    35  	listScenarios([]*gauge.Specification{buildTestSpecification()}, func(res []string) {
    36  		verifyUniqueness(res, []string{"scenario1"}, t)
    37  	})
    38  }
    39  
    40  func TestOnlyUniqueStepsAreReturned(t *testing.T) {
    41  	connectToRunner = func() (runner.Runner, error) {
    42  		return &mockRunner{
    43  			response: &gauge_messages.Message{
    44  				StepNamesResponse: &gauge_messages.StepNamesResponse{
    45  					Steps: []string{
    46  						"Vowels are <vowelString>.",
    47  						"Vowels in English language are <vowelString>.",
    48  						"The word <word> has <expectedCount> vowels.",
    49  						"Almost all words have vowels <wordsTable>",
    50  					},
    51  				},
    52  			},
    53  		}, nil
    54  	}
    55  	expected := []string{
    56  		"Almost all words have vowels <wordsTable>",
    57  		"The word <word> has <expectedCount> vowels.",
    58  		"Vowels are <vowelString>.",
    59  		"Vowels in English language are <vowelString>.",
    60  	}
    61  	listSteps([]*gauge.Specification{buildTestSpecification()}, func(res []string) {
    62  		verifyUniqueness(res, expected, t)
    63  	})
    64  }
    65  
    66  func buildTestSpecification() *gauge.Specification {
    67  	return &gauge.Specification{
    68  		Heading: &gauge.Heading{
    69  			Value: "Spec1",
    70  		},
    71  		Scenarios: []*gauge.Scenario{
    72  			{
    73  				Heading: &gauge.Heading{
    74  					Value: "scenario1",
    75  				},
    76  				Tags: &gauge.Tags{
    77  					RawValues: [][]string{{"foo"}, {"bar"}},
    78  				},
    79  				Steps: []*gauge.Step{
    80  					{
    81  						Value:     "scenario1#step1",
    82  						LineText:  "not important",
    83  						IsConcept: false,
    84  					},
    85  				}},
    86  			{
    87  				Heading: &gauge.Heading{
    88  					Value: "scenario1",
    89  				},
    90  				Tags: &gauge.Tags{
    91  					RawValues: [][]string{{"foo"}},
    92  				},
    93  				Steps: []*gauge.Step{
    94  					{
    95  						Value:     "scenario2#step1",
    96  						LineText:  "not important",
    97  						IsConcept: false,
    98  					},
    99  				}},
   100  		},
   101  		TearDownSteps: []*gauge.Step{},
   102  	}
   103  }
   104  
   105  func verifyUniqueness(actual []string, wanted []string, t *testing.T) {
   106  	if !reflect.DeepEqual(actual, wanted) {
   107  		t.Errorf("wanted: `%s`,\n got: `%s` ", wanted, actual)
   108  	}
   109  }