e2e_kubeadm_suite_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package kubeadm
  14. import (
  15. "flag"
  16. "fmt"
  17. "os"
  18. "path/filepath"
  19. "testing"
  20. "github.com/onsi/ginkgo"
  21. "github.com/onsi/ginkgo/config"
  22. "github.com/onsi/gomega"
  23. "github.com/spf13/pflag"
  24. morereporters "github.com/onsi/ginkgo/reporters"
  25. "k8s.io/kubernetes/test/e2e/framework"
  26. e2econfig "k8s.io/kubernetes/test/e2e/framework/config"
  27. )
  28. func TestMain(m *testing.M) {
  29. // Copy go flags in TestMain, to ensure go test flags are registered (no longer available in init() as of go1.13)
  30. e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
  31. framework.RegisterCommonFlags(flag.CommandLine)
  32. framework.RegisterClusterFlags(flag.CommandLine)
  33. pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
  34. pflag.Parse()
  35. framework.AfterReadingAllFlags(&framework.TestContext)
  36. os.Exit(m.Run())
  37. }
  38. func TestE2E(t *testing.T) {
  39. gomega.RegisterFailHandler(ginkgo.Fail)
  40. reporters := []ginkgo.Reporter{}
  41. reportDir := framework.TestContext.ReportDir
  42. if reportDir != "" {
  43. // Create the directory if it doesn't already exists
  44. if err := os.MkdirAll(reportDir, 0755); err != nil {
  45. t.Fatalf("Failed creating report directory: %v", err)
  46. } else {
  47. // Configure a junit reporter to write to the directory
  48. junitFile := fmt.Sprintf("junit_%s_%02d.xml", framework.TestContext.ReportPrefix, config.GinkgoConfig.ParallelNode)
  49. junitPath := filepath.Join(reportDir, junitFile)
  50. reporters = append(reporters, morereporters.NewJUnitReporter(junitPath))
  51. }
  52. }
  53. ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "E2EKubeadm suite", reporters)
  54. }