viz_test.go 2.0 KB

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