windows_os_string_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package operatingsystem
  2. import (
  3. "testing"
  4. )
  5. func Test_windowsOSRelease_String(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. r windowsOSRelease
  9. want string
  10. }{
  11. {
  12. name: "Flavor=client/DisplayVersion=yes/UBR=yes",
  13. r: windowsOSRelease{
  14. DisplayVersion: "1809",
  15. Build: 17763,
  16. UBR: 2628,
  17. },
  18. want: "Microsoft Windows Version 1809 (OS Build 17763.2628)",
  19. },
  20. {
  21. name: "Flavor=client/DisplayVersion=yes/UBR=no",
  22. r: windowsOSRelease{
  23. DisplayVersion: "1809",
  24. Build: 17763,
  25. },
  26. want: "Microsoft Windows Version 1809 (OS Build 17763)",
  27. },
  28. {
  29. name: "Flavor=client/DisplayVersion=no/UBR=yes",
  30. r: windowsOSRelease{
  31. Build: 17763,
  32. UBR: 1879,
  33. },
  34. want: "Microsoft Windows (OS Build 17763.1879)",
  35. },
  36. {
  37. name: "Flavor=client/DisplayVersion=no/UBR=no",
  38. r: windowsOSRelease{
  39. Build: 10240,
  40. },
  41. want: "Microsoft Windows (OS Build 10240)",
  42. },
  43. {
  44. name: "Flavor=server/DisplayVersion=yes/UBR=yes",
  45. r: windowsOSRelease{
  46. IsServer: true,
  47. DisplayVersion: "21H2",
  48. Build: 20348,
  49. UBR: 169,
  50. },
  51. want: "Microsoft Windows Server Version 21H2 (OS Build 20348.169)",
  52. },
  53. {
  54. name: "Flavor=server/DisplayVersion=yes/UBR=no",
  55. r: windowsOSRelease{
  56. IsServer: true,
  57. DisplayVersion: "20H2",
  58. Build: 19042,
  59. },
  60. want: "Microsoft Windows Server Version 20H2 (OS Build 19042)",
  61. },
  62. {
  63. name: "Flavor=server/DisplayVersion=no/UBR=yes",
  64. r: windowsOSRelease{
  65. IsServer: true,
  66. Build: 17763,
  67. UBR: 107,
  68. },
  69. want: "Microsoft Windows Server (OS Build 17763.107)",
  70. },
  71. {
  72. name: "Flavor=server/DisplayVersion=no/UBR=no",
  73. r: windowsOSRelease{
  74. IsServer: true,
  75. Build: 17763,
  76. },
  77. want: "Microsoft Windows Server (OS Build 17763)",
  78. },
  79. }
  80. for _, tt := range tests {
  81. t.Run(tt.name, func(t *testing.T) {
  82. if got := tt.r.String(); got != tt.want {
  83. t.Errorf("windowsOSRelease.String() = %v, want %v", got, tt.want)
  84. }
  85. })
  86. }
  87. }