You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

  1. // Copyright (c) 2015-2024 MinIO, Inc.
  2. //
  3. // This file is part of MinIO Object Storage stack
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. package cmd
  18. import (
  19. "slices"
  20. "testing"
  21. "gopkg.in/yaml.v3"
  22. )
  23. func TestBatchJobPrefix_UnmarshalYAML(t *testing.T) {
  24. type args struct {
  25. yamlStr string
  26. }
  27. type PrefixTemp struct {
  28. Prefix BatchJobPrefix `yaml:"prefix"`
  29. }
  30. tests := []struct {
  31. name string
  32. b PrefixTemp
  33. args args
  34. want []string
  35. wantErr bool
  36. }{
  37. {
  38. name: "test1",
  39. b: PrefixTemp{},
  40. args: args{
  41. yamlStr: `
  42. prefix: "foo"
  43. `,
  44. },
  45. want: []string{"foo"},
  46. wantErr: false,
  47. },
  48. {
  49. name: "test2",
  50. b: PrefixTemp{},
  51. args: args{
  52. yamlStr: `
  53. prefix:
  54. - "foo"
  55. - "bar"
  56. `,
  57. },
  58. want: []string{"foo", "bar"},
  59. },
  60. }
  61. for _, tt := range tests {
  62. t.Run(tt.name, func(t *testing.T) {
  63. if err := yaml.Unmarshal([]byte(tt.args.yamlStr), &tt.b); (err != nil) != tt.wantErr {
  64. t.Errorf("UnmarshalYAML() error = %v, wantErr %v", err, tt.wantErr)
  65. }
  66. if !slices.Equal(tt.b.Prefix.F(), tt.want) {
  67. t.Errorf("UnmarshalYAML() = %v, want %v", tt.b.Prefix.F(), tt.want)
  68. }
  69. })
  70. }
  71. }