diff --git a/test/conformance/BUILD b/test/conformance/BUILD index 16dec712176..6716bbe7d40 100644 --- a/test/conformance/BUILD +++ b/test/conformance/BUILD @@ -33,8 +33,7 @@ filegroup( srcs = [ ":package-srcs", "//test/conformance/behaviors:all-srcs", - "//test/conformance/kubetestgen:all-srcs", - "//test/conformance/kubetestlink:all-srcs", + "//test/conformance/kubeconform:all-srcs", ], tags = ["automanaged"], visibility = ["//visibility:public"], diff --git a/test/conformance/kubetestgen/.gitignore b/test/conformance/kubeconform/.gitignore similarity index 100% rename from test/conformance/kubetestgen/.gitignore rename to test/conformance/kubeconform/.gitignore diff --git a/test/conformance/kubetestgen/BUILD b/test/conformance/kubeconform/BUILD similarity index 83% rename from test/conformance/kubetestgen/BUILD rename to test/conformance/kubeconform/BUILD index 3ad33a7eafe..20e7fefa374 100644 --- a/test/conformance/kubetestgen/BUILD +++ b/test/conformance/kubeconform/BUILD @@ -2,8 +2,12 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") go_library( name = "go_default_library", - srcs = ["kubetestgen.go"], - importpath = "k8s.io/kubernetes/test/conformance/kubetestgen", + srcs = [ + "gen.go", + "kubeconform.go", + "link.go", + ], + importpath = "k8s.io/kubernetes/test/conformance/kubeconform", visibility = ["//visibility:private"], deps = [ "//test/conformance/behaviors:go_default_library", @@ -29,7 +33,7 @@ filegroup( ) go_binary( - name = "kubetestgen", + name = "kubeconform", data = ["//api/openapi-spec"], embed = [":go_default_library"], visibility = ["//visibility:public"], diff --git a/test/conformance/kubetestgen/README.md b/test/conformance/kubeconform/README.md similarity index 100% rename from test/conformance/kubetestgen/README.md rename to test/conformance/kubeconform/README.md diff --git a/test/conformance/kubetestgen/kubetestgen.go b/test/conformance/kubeconform/gen.go similarity index 91% rename from test/conformance/kubetestgen/kubetestgen.go rename to test/conformance/kubeconform/gen.go index c47e96baca5..9962e3efc34 100644 --- a/test/conformance/kubetestgen/kubetestgen.go +++ b/test/conformance/kubeconform/gen.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "flag" "fmt" "os" "sort" @@ -30,29 +29,10 @@ import ( "k8s.io/kubernetes/test/conformance/behaviors" ) -type options struct { - schemaPath string - resource string - area string - behaviorsDir string -} - -func parseFlags() *options { - o := &options{} - flag.StringVar(&o.schemaPath, "schema", "", "Path to the OpenAPI schema") - flag.StringVar(&o.resource, "resource", ".*", "Resource name") - flag.StringVar(&o.area, "area", "default", "Area name to use") - flag.StringVar(&o.behaviorsDir, "dir", "../behaviors/", "Path to the behaviors directory") - flag.Parse() - return o -} - var defMap map[string]analysis.SchemaRef -func main() { +func gen(o *options) { defMap = make(map[string]analysis.SchemaRef) - o := parseFlags() - d, err := loads.JSONSpec(o.schemaPath) if err != nil { fmt.Printf("ERROR: %s\n", err.Error()) diff --git a/test/conformance/kubeconform/kubeconform.go b/test/conformance/kubeconform/kubeconform.go new file mode 100644 index 00000000000..941e94a99a4 --- /dev/null +++ b/test/conformance/kubeconform/kubeconform.go @@ -0,0 +1,64 @@ +/* +Copyright 2020 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + "fmt" +) + +type options struct { + // Flags only used for generating behaviors + schemaPath string + resource string + area string + + // Flags only used for linking behaviors + testdata string + listMissing bool + + // Flags shared between CLI tools + behaviorsDir string +} + +func parseFlags() *options { + o := &options{} + + flag.StringVar(&o.schemaPath, "schema", "", "Path to the OpenAPI schema") + flag.StringVar(&o.resource, "resource", ".*", "Resource name") + flag.StringVar(&o.area, "area", "default", "Area name to use") + + flag.StringVar(&o.testdata, "testdata", "../testdata/conformance.yaml", "YAML file containing test linkage data") + flag.BoolVar(&o.listMissing, "missing", true, "Only list behaviors missing tests") + + flag.StringVar(&o.behaviorsDir, "dir", "../behaviors", "Path to the behaviors directory") + + flag.Parse() + return o +} + +func main() { + o := parseFlags() + action := flag.Arg(0) + if action == "gen" { + gen(o) + } else if action == "link" { + link(o) + } else { + fmt.Printf("Unknown argument %s\n", action) + } +} diff --git a/test/conformance/kubetestlink/kubetestlink.go b/test/conformance/kubeconform/link.go similarity index 82% rename from test/conformance/kubetestlink/kubetestlink.go rename to test/conformance/kubeconform/link.go index 91be0314c27..486ecbb2463 100644 --- a/test/conformance/kubetestlink/kubetestlink.go +++ b/test/conformance/kubeconform/link.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "flag" "fmt" "io/ioutil" "os" @@ -29,24 +28,7 @@ import ( "k8s.io/kubernetes/test/conformance/behaviors" ) -type options struct { - behaviorsDir string - testdata string - listMissing bool -} - -func parseFlags() *options { - o := &options{} - flag.StringVar(&o.behaviorsDir, "behaviors", "../behaviors/", "Path to the behaviors directory") - flag.StringVar(&o.testdata, "testdata", "../testdata/conformance.yaml", "YAML file containing test linkage data") - flag.BoolVar(&o.listMissing, "missing", true, "Only list behaviors missing tests") - flag.Parse() - return o -} - -func main() { - o := parseFlags() - +func link(o *options) { var behaviorFiles []string behaviorsMapping := make(map[string][]string) var conformanceDataList []behaviors.ConformanceData @@ -66,6 +48,7 @@ func main() { fmt.Printf("%v", err) return } + fmt.Printf("%v", behaviorFiles) for _, behaviorFile := range behaviorFiles { var suite behaviors.Suite @@ -87,6 +70,10 @@ func main() { } conformanceYaml, err := ioutil.ReadFile(o.testdata) + if err != nil { + fmt.Printf("%v", err) + return + } err = yaml.Unmarshal(conformanceYaml, &conformanceDataList) if err != nil { diff --git a/test/conformance/kubetestlink/BUILD b/test/conformance/kubetestlink/BUILD deleted file mode 100644 index e7a2dd28ae1..00000000000 --- a/test/conformance/kubetestlink/BUILD +++ /dev/null @@ -1,32 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - -go_library( - name = "go_default_library", - srcs = ["kubetestlink.go"], - importpath = "k8s.io/kubernetes/test/conformance/kubetestlink", - visibility = ["//visibility:private"], - deps = [ - "//test/conformance/behaviors:go_default_library", - "//vendor/gopkg.in/yaml.v2:go_default_library", - ], -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], - visibility = ["//visibility:public"], -) - -go_binary( - name = "kubetestlink", - embed = [":go_default_library"], - visibility = ["//visibility:public"], -)