code_generation_test.bzl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright 2018 The Kubernetes Authors.
  2. #
  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. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. load(":code_generation.bzl", "bazel_go_library", "go_pkg")
  15. load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
  16. def _bazel_go_library_test_impl(ctx):
  17. env = unittest.begin(ctx)
  18. test_cases = [
  19. ("pkg/kubectl/util", "//pkg/kubectl/util:go_default_library"),
  20. ("vendor/some/third/party", "//vendor/some/third/party:go_default_library"),
  21. ("staging/src/k8s.io/apimachinery/api", "//staging/src/k8s.io/apimachinery/api:go_default_library"),
  22. ]
  23. for input, expected in test_cases:
  24. asserts.equals(env, expected, bazel_go_library(input))
  25. unittest.end(env)
  26. bazel_go_library_test = unittest.make(_bazel_go_library_test_impl)
  27. def _go_pkg_test_impl(ctx):
  28. env = unittest.begin(ctx)
  29. test_cases = [
  30. ("pkg/kubectl/util", "k8s.io/kubernetes/pkg/kubectl/util"),
  31. ("vendor/some/third/party", "k8s.io/kubernetes/vendor/some/third/party"),
  32. ("staging/src/k8s.io/apimachinery/api", "k8s.io/kubernetes/vendor/k8s.io/apimachinery/api"),
  33. ]
  34. for input, expected in test_cases:
  35. asserts.equals(env, expected, go_pkg(input))
  36. unittest.end(env)
  37. go_pkg_test = unittest.make(_go_pkg_test_impl)
  38. def code_generation_test_suite(name):
  39. unittest.suite(
  40. name,
  41. bazel_go_library_test,
  42. go_pkg_test,
  43. )