sts_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build !plan9
  4. package main
  5. import (
  6. "testing"
  7. )
  8. // Test_statefulSetNameBase tests that parent name portion in a StatefulSet name
  9. // base will be truncated if the parent name is longer than 43 chars to ensure
  10. // that the total does not exceed 52 chars.
  11. // How many chars need to be cut off parent name depends on an internal var in
  12. // kube name generation code that can change at which point this test will break
  13. // and need to be changed. This is okay as we do not rely on that value in
  14. // code whilst being aware when it changes might still be useful.
  15. // https://github.com/kubernetes/kubernetes/blob/v1.28.4/staging/src/k8s.io/apiserver/pkg/storage/names/generate.go#L45.
  16. // https://github.com/kubernetes/kubernetes/pull/116430
  17. func Test_statefulSetNameBase(t *testing.T) {
  18. tests := []struct {
  19. name string
  20. in string
  21. out string
  22. }{
  23. {
  24. name: "43 chars",
  25. in: "oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9xb",
  26. out: "ts-oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9xb-",
  27. },
  28. {
  29. name: "44 chars",
  30. in: "oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9xbo",
  31. out: "ts-oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9xb-",
  32. },
  33. {
  34. name: "42 chars",
  35. in: "oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9x",
  36. out: "ts-oidhexl9o832hcbhyg4uz6o0s7u9uae54h5k8ofs9x-",
  37. },
  38. }
  39. for _, tt := range tests {
  40. t.Run(tt.name, func(t *testing.T) {
  41. if got := statefulSetNameBase(tt.in); got != tt.out {
  42. t.Errorf("stsNamePrefix(%s) = %q, want %s", tt.in, got, tt.out)
  43. }
  44. })
  45. }
  46. }