...

Source file src/k8s.io/kubernetes/test/e2e/framework/skipper/skipper_test.go

Documentation: k8s.io/kubernetes/test/e2e/framework/skipper

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package skipper_test
    18  
    19  import (
    20  	"flag"
    21  	"testing"
    22  
    23  	"github.com/onsi/ginkgo/v2"
    24  	"github.com/onsi/ginkgo/v2/reporters"
    25  
    26  	"k8s.io/kubernetes/test/e2e/framework"
    27  	"k8s.io/kubernetes/test/e2e/framework/internal/output"
    28  	e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
    29  )
    30  
    31  // The line number of the following code is checked in TestFailureOutput below.
    32  // Be careful when moving it around or changing the import statements above.
    33  // Here are some intentionally blank lines that can be removed to compensate
    34  // for future additional import statements.
    35  //
    36  //
    37  //
    38  //
    39  //
    40  //
    41  //
    42  //
    43  //
    44  //
    45  //
    46  //
    47  //
    48  //
    49  //
    50  //
    51  // This must be line #50.
    52  
    53  var _ = ginkgo.Describe("e2e", func() {
    54  	ginkgo.It("skips", func() {
    55  		e2eskipper.Skipf("skipping %d, %d, %d", 1, 3, 4)
    56  	})
    57  })
    58  
    59  func TestSkip(t *testing.T) {
    60  	// This simulates how test/e2e uses the framework and how users
    61  	// invoke test/e2e.
    62  	framework.RegisterCommonFlags(flag.CommandLine)
    63  	framework.RegisterClusterFlags(flag.CommandLine)
    64  	for flagname, value := range map[string]string{
    65  		// This simplifies the text comparison.
    66  		"ginkgo.no-color": "true",
    67  	} {
    68  		if err := flag.Set(flagname, value); err != nil {
    69  			t.Fatalf("set %s: %v", flagname, err)
    70  		}
    71  	}
    72  	framework.AfterReadingAllFlags(&framework.TestContext)
    73  	suiteConfig, reporterConfig := framework.CreateGinkgoConfig()
    74  	reporterConfig.Verbose = true
    75  
    76  	expected := output.TestResult{
    77  		Suite: reporters.JUnitTestSuite{
    78  			Tests:    1,
    79  			Failures: 0,
    80  			Errors:   0,
    81  			Disabled: 0,
    82  			Skipped:  1,
    83  			TestCases: []reporters.JUnitTestCase{
    84  				{
    85  					Name:   "[It] e2e skips",
    86  					Status: "skipped",
    87  					Skipped: &reporters.JUnitSkipped{
    88  						Message: `skipped - skipping 1, 3, 4`,
    89  					},
    90  				},
    91  			},
    92  		},
    93  	}
    94  
    95  	output.TestGinkgoOutput(t, expected, suiteConfig, reporterConfig)
    96  }
    97  

View as plain text