github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/labels_test.go (about)

     1  package internal_integration_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  
     7  	. "github.com/onsi/ginkgo/internal/test_helpers"
     8  	"github.com/onsi/ginkgo/types"
     9  )
    10  
    11  var _ = Describe("Labels", func() {
    12  	Describe("when a suite has labelled tests", func() {
    13  		fixture := func() {
    14  			Describe("outer container", func() {
    15  				It("A", rt.T("A"), Focus, Label("cat"))
    16  				It("B", rt.T("B"), Label("dog"))
    17  				Describe("container", Label("cow", "cat"), func() {
    18  					It("C", rt.T("C"))
    19  					It("D", rt.T("D"), Label("fish", "cat"))
    20  				})
    21  				Describe("other container", Label("     giraffe     "), func() {
    22  					It("E", rt.T("E"))
    23  					It("F", rt.T("F"), Label("dog"))
    24  
    25  					Describe("inner container", Label("cow"), func() {
    26  						It("G", rt.T("G"), Pending, Label("fish", "chicken"))
    27  						It("H", rt.T("H"), Label("fish", "chicken"))
    28  					})
    29  				})
    30  			})
    31  		}
    32  		BeforeEach(func() {
    33  			conf.LabelFilter = "TopLevelLabel && (dog || cow)"
    34  			success, hPF := RunFixture("labelled tests", fixture)
    35  			Ω(success).Should(BeTrue())
    36  			Ω(hPF).Should(BeFalse())
    37  		})
    38  
    39  		It("includes the labels in the spec report", func() {
    40  			Ω(reporter.Did.Find("A").ContainerHierarchyLabels).Should(Equal([][]string{{}}))
    41  			Ω(reporter.Did.Find("A").LeafNodeLabels).Should(Equal([]string{"cat"}))
    42  			Ω(reporter.Did.Find("A").Labels()).Should(Equal([]string{"cat"}))
    43  
    44  			Ω(reporter.Did.Find("B").ContainerHierarchyLabels).Should(Equal([][]string{{}}))
    45  			Ω(reporter.Did.Find("B").LeafNodeLabels).Should(Equal([]string{"dog"}))
    46  			Ω(reporter.Did.Find("B").Labels()).Should(Equal([]string{"dog"}))
    47  
    48  			Ω(reporter.Did.Find("C").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"cow", "cat"}}))
    49  			Ω(reporter.Did.Find("C").LeafNodeLabels).Should(Equal([]string{}))
    50  			Ω(reporter.Did.Find("C").Labels()).Should(Equal([]string{"cow", "cat"}))
    51  
    52  			Ω(reporter.Did.Find("D").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"cow", "cat"}}))
    53  			Ω(reporter.Did.Find("D").LeafNodeLabels).Should(Equal([]string{"fish", "cat"}))
    54  			Ω(reporter.Did.Find("D").Labels()).Should(Equal([]string{"cow", "cat", "fish"}))
    55  
    56  			Ω(reporter.Did.Find("E").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"giraffe"}}))
    57  			Ω(reporter.Did.Find("E").LeafNodeLabels).Should(Equal([]string{}))
    58  			Ω(reporter.Did.Find("E").Labels()).Should(Equal([]string{"giraffe"}))
    59  
    60  			Ω(reporter.Did.Find("F").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"giraffe"}}))
    61  			Ω(reporter.Did.Find("F").LeafNodeLabels).Should(Equal([]string{"dog"}))
    62  			Ω(reporter.Did.Find("F").Labels()).Should(Equal([]string{"giraffe", "dog"}))
    63  
    64  			Ω(reporter.Did.Find("G").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"giraffe"}, {"cow"}}))
    65  			Ω(reporter.Did.Find("G").LeafNodeLabels).Should(Equal([]string{"fish", "chicken"}))
    66  			Ω(reporter.Did.Find("G").Labels()).Should(Equal([]string{"giraffe", "cow", "fish", "chicken"}))
    67  
    68  			Ω(reporter.Did.Find("H").ContainerHierarchyLabels).Should(Equal([][]string{{}, {"giraffe"}, {"cow"}}))
    69  			Ω(reporter.Did.Find("H").LeafNodeLabels).Should(Equal([]string{"fish", "chicken"}))
    70  			Ω(reporter.Did.Find("H").Labels()).Should(Equal([]string{"giraffe", "cow", "fish", "chicken"}))
    71  		})
    72  
    73  		It("includes suite labels in the suite report", func() {
    74  			Ω(reporter.Begin.SuiteLabels).Should(Equal([]string{"TopLevelLabel"}))
    75  			Ω(reporter.End.SuiteLabels).Should(Equal([]string{"TopLevelLabel"}))
    76  		})
    77  
    78  		It("honors the LabelFilter config and skips tests appropriately", func() {
    79  			Ω(rt).Should(HaveTracked("B", "C", "D", "F", "H"))
    80  			Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("B", "C", "D", "F", "H"))
    81  			Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("A", "E"))
    82  			Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("G"))
    83  			Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(5), NSkipped(2), NPending(1), NSpecs(8), NWillRun(5)))
    84  		})
    85  	})
    86  
    87  	Context("when a suite-level label is filtered out by the label-filter", func() {
    88  		BeforeEach(func() {
    89  			conf.LabelFilter = "!TopLevelLabel"
    90  			success, hPF := RunFixture("labelled tests", func() {
    91  				BeforeSuite(rt.T("before-suite"))
    92  				Describe("outer container", func() {
    93  					It("A", rt.T("A"))
    94  					It("B", rt.T("B"))
    95  				})
    96  				ReportAfterEach(func(r SpecReport) {
    97  					rt.Run("RAE-" + r.LeafNodeText)
    98  				})
    99  				AfterSuite(rt.T("after-suite"))
   100  				ReportAfterSuite("AfterSuite", func(r Report) {
   101  					rt.Run("RAS")
   102  				})
   103  			})
   104  			Ω(success).Should(BeTrue())
   105  			Ω(hPF).Should(BeFalse())
   106  		})
   107  
   108  		It("doesn't run anything except for reporters", func() {
   109  			Ω(rt).Should(HaveTracked("RAE-A", "RAE-B", "RAS"))
   110  		})
   111  
   112  		It("skip severything", func() {
   113  			Ω(reporter.Did.Find("A")).Should(HaveBeenSkipped())
   114  			Ω(reporter.Did.Find("B")).Should(HaveBeenSkipped())
   115  		})
   116  	})
   117  })