|
| 1 | +/* |
| 2 | +Copyright 2017 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 main |
| 18 | + |
| 19 | +import ( |
| 20 | + "flag" |
| 21 | + "fmt" |
| 22 | + "os" |
| 23 | + "path" |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/onsi/ginkgo" |
| 27 | + "github.com/onsi/ginkgo/reporters" |
| 28 | + "github.com/onsi/gomega" |
| 29 | + |
| 30 | + "github.com/kubernetes-incubator/cri-tools/pkg/framework" |
| 31 | + |
| 32 | + _ "github.com/kubernetes-incubator/cri-tools/pkg/benchmark" |
| 33 | + _ "github.com/kubernetes-incubator/cri-tools/pkg/validate" |
| 34 | +) |
| 35 | + |
| 36 | +var ( |
| 37 | + isBenchMark = flag.Bool("benchmark", false, "Run benchmarks instead of validation tests") |
| 38 | +) |
| 39 | + |
| 40 | +func init() { |
| 41 | + framework.RegisterFlags() |
| 42 | +} |
| 43 | + |
| 44 | +// runTestSuite runs cri validation tests and benchmark tests. |
| 45 | +func runTestSuite(t *testing.T) { |
| 46 | + gomega.RegisterFailHandler(ginkgo.Fail) |
| 47 | + |
| 48 | + if *isBenchMark { |
| 49 | + flag.Set("ginkgo.focus", "benchmark") |
| 50 | + } else { |
| 51 | + // Skip benchamark measurements for validation tests. |
| 52 | + flag.Set("ginkgo.skipMeasurements", "true") |
| 53 | + } |
| 54 | + |
| 55 | + reporter := []ginkgo.Reporter{} |
| 56 | + if framework.TestContext.ReportDir != "" { |
| 57 | + if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil { |
| 58 | + t.Errorf("Failed creating report directory: %v", err) |
| 59 | + } |
| 60 | + |
| 61 | + reporter = append(reporter, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, fmt.Sprintf("junit_%v.xml", framework.TestContext.ReportPrefix)))) |
| 62 | + } |
| 63 | + |
| 64 | + ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "CRI validation", reporter) |
| 65 | +} |
| 66 | + |
| 67 | +func TestCRISuite(t *testing.T) { |
| 68 | + runTestSuite(t) |
| 69 | +} |
0 commit comments