|
| 1 | +package alinas |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAddAutoFallbackNFSMountOptions(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + inputOptions []string |
| 13 | + expected []string |
| 14 | + }{ |
| 15 | + { |
| 16 | + name: "Empty options", |
| 17 | + inputOptions: []string{}, |
| 18 | + expected: []string{}, |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "EFC without VSC should add both no_add_cgroup and auto_fallback_nfs", |
| 22 | + inputOptions: []string{"efc"}, |
| 23 | + expected: []string{"efc", "no_add_cgroup", "auto_fallback_nfs"}, |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "EFC with VSC should only add no_add_cgroup", |
| 27 | + inputOptions: []string{"efc", "net=vsc"}, |
| 28 | + expected: []string{"efc", "net=vsc", "no_add_cgroup"}, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "EFC with non-VSC net option should add both options", |
| 32 | + inputOptions: []string{"efc", "net=other"}, |
| 33 | + expected: []string{"efc", "net=other", "no_add_cgroup", "auto_fallback_nfs"}, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "Multiple options with EFC but no VSC", |
| 37 | + inputOptions: []string{"rw", "efc", "hard"}, |
| 38 | + expected: []string{"rw", "efc", "hard", "no_add_cgroup", "auto_fallback_nfs"}, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "Multiple options with EFC and VSC", |
| 42 | + inputOptions: []string{"rw", "efc", "net=vsc", "hard"}, |
| 43 | + expected: []string{"rw", "efc", "net=vsc", "hard", "no_add_cgroup"}, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "No EFC should not add any options", |
| 47 | + inputOptions: []string{"rw", "hard"}, |
| 48 | + expected: []string{"rw", "hard"}, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "Comma-separated options with EFC but no VSC", |
| 52 | + inputOptions: []string{"rw,efc,hard"}, |
| 53 | + expected: []string{"rw,efc,hard", "no_add_cgroup", "auto_fallback_nfs"}, |
| 54 | + }, |
| 55 | + { |
| 56 | + name: "Comma-separated options with EFC and VSC", |
| 57 | + inputOptions: []string{"rw,efc,net=vsc,hard"}, |
| 58 | + expected: []string{"rw,efc,net=vsc,hard", "no_add_cgroup"}, |
| 59 | + }, |
| 60 | + { |
| 61 | + name: "Empty option string in slice", |
| 62 | + inputOptions: []string{"", "efc"}, |
| 63 | + expected: []string{"", "efc", "no_add_cgroup", "auto_fallback_nfs"}, |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + for _, tt := range tests { |
| 68 | + t.Run(tt.name, func(t *testing.T) { |
| 69 | + result := addAutoFallbackNFSMountOptions(tt.inputOptions) |
| 70 | + assert.Equal(t, tt.expected, result) |
| 71 | + }) |
| 72 | + } |
| 73 | +} |
0 commit comments