viz_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Copyright 2020 Docker Compose CLI 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 compose
  14. import (
  15. "testing"
  16. "gotest.tools/v3/assert"
  17. )
  18. func TestPreferredIndentationStr(t *testing.T) {
  19. type args struct {
  20. size int
  21. useSpace bool
  22. }
  23. tests := []struct {
  24. name string
  25. args args
  26. want string
  27. wantErr bool
  28. }{
  29. {
  30. name: "should return '\\t\\t'",
  31. args: args{
  32. size: 2,
  33. useSpace: false,
  34. },
  35. want: "\t\t",
  36. wantErr: false,
  37. },
  38. {
  39. name: "should return ' '",
  40. args: args{
  41. size: 4,
  42. useSpace: true,
  43. },
  44. want: " ",
  45. wantErr: false,
  46. },
  47. {
  48. name: "should return ''",
  49. args: args{
  50. size: 0,
  51. useSpace: false,
  52. },
  53. want: "",
  54. wantErr: false,
  55. },
  56. {
  57. name: "should return ''",
  58. args: args{
  59. size: 0,
  60. useSpace: true,
  61. },
  62. want: "",
  63. wantErr: false,
  64. },
  65. {
  66. name: "should throw error because indentation size < 0",
  67. args: args{
  68. size: -1,
  69. useSpace: false,
  70. },
  71. want: "",
  72. wantErr: true,
  73. },
  74. }
  75. for _, tt := range tests {
  76. t.Run(tt.name, func(t *testing.T) {
  77. got, err := preferredIndentationStr(tt.args.size, tt.args.useSpace)
  78. if tt.wantErr {
  79. assert.ErrorContains(t, err, "invalid indentation size", "preferredIndentationStr(%v,%v)", tt.args.size, tt.args.useSpace)
  80. } else {
  81. assert.NilError(t, err)
  82. assert.Equal(t, tt.want, got)
  83. }
  84. })
  85. }
  86. }