(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestCheckFileNameValidity(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | input string |
| 19 | wantErr bool |
| 20 | errMsg string |
| 21 | }{ |
| 22 | {name: "Invalid - single dot", |
| 23 | input: ".", |
| 24 | wantErr: true, |
| 25 | errMsg: "file name cannot be '.' or '..'", |
| 26 | }, { |
| 27 | name: "invalid - double dot", |
| 28 | input: "..", |
| 29 | wantErr: true, |
| 30 | errMsg: "file name cannot be '.' or '..'", |
| 31 | }, { |
| 32 | name: "invalid - ends with /.. (platform separator)", |
| 33 | input: fmt.Sprintf("testDir%c..", filepath.Separator), |
| 34 | wantErr: true, |
| 35 | errMsg: fmt.Sprintf("file name cannot end with '%c.' or '%c..'", filepath.Separator, filepath.Separator), |
| 36 | }, { |
| 37 | name: "invalid - ends with /. (platform separator)", |
| 38 | input: fmt.Sprintf("testDir%c.", filepath.Separator), |
| 39 | wantErr: true, |
| 40 | errMsg: fmt.Sprintf("file name cannot end with '%c.' or '%c..'", filepath.Separator, filepath.Separator), |
| 41 | }, { |
| 42 | name: "valid - normal file name", |
| 43 | input: "valid_file.txt", |
| 44 | wantErr: false, |
| 45 | }, |
| 46 | { |
| 47 | name: "valid - contains dot inside", |
| 48 | input: "some.folder.name/file.txt", |
| 49 | wantErr: false, |
| 50 | }, |
| 51 | { |
| 52 | name: "valid - ends with dot not after separator", |
| 53 | input: "somefile.", |
| 54 | wantErr: false, |
| 55 | }, |
| 56 | { |
| 57 | name: "valid - ends with .. not after separator", |
| 58 | input: "somefile..", |
| 59 | wantErr: false, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | for _, tt := range tests { |
| 64 | t.Run(tt.name, func(t *testing.T) { |
| 65 | err := checkFileNameValidity(tt.input) |
| 66 | |
| 67 | if !tt.wantErr { |
| 68 | require.NoError(t, err) |
| 69 | } else { |
| 70 | require.Error(t, err) |
| 71 | assert.Contains(t, err.Error(), tt.errMsg) |
| 72 | } |
nothing calls this directly
no test coverage detected