(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestIsFileReadable(t *testing.T) { |
| 18 | tmpFolderLocation := "" |
| 19 | tmpPrefix := "util_test" |
| 20 | |
| 21 | tmpDir, err := os.MkdirTemp(tmpFolderLocation, tmpPrefix) |
| 22 | assert.NoError(t, err) |
| 23 | defer func() { |
| 24 | assert.NoError(t, os.RemoveAll(tmpDir)) |
| 25 | }() |
| 26 | p := path.Join(tmpDir, "x") |
| 27 | f, i, err := IsFileReadable(p, false) |
| 28 | assert.Error(t, err) |
| 29 | assert.Empty(t, f) |
| 30 | assert.Nil(t, i) |
| 31 | |
| 32 | assert.NoError(t, os.WriteFile(p, []byte("data"), os.ModePerm)) // #nosec G306 |
| 33 | f, i, err = IsFileReadable(p, false) |
| 34 | assert.NoError(t, err) |
| 35 | assert.Equal(t, p, f) |
| 36 | assert.NotNil(t, i) |
| 37 | assert.Equal(t, p, f) |
| 38 | |
| 39 | noExt := path.Join(tmpDir, "y") |
| 40 | p = path.Join(tmpDir, "y.png") |
| 41 | _, _, err = IsFileReadable(noExt, false) |
| 42 | assert.Error(t, err) |
| 43 | |
| 44 | assert.NoError(t, os.WriteFile(p, []byte("data"), os.ModePerm)) // #nosec G306 |
| 45 | _, _, err = IsFileReadable(noExt, false) |
| 46 | assert.Error(t, err) |
| 47 | |
| 48 | f, i, err = IsFileReadable(noExt, true) |
| 49 | assert.NoError(t, err) |
| 50 | assert.Equal(t, p, f) |
| 51 | assert.NotNil(t, i) |
| 52 | assert.Equal(t, p, f) |
| 53 | } |
| 54 | |
| 55 | func TestUploadFile(t *testing.T) { |
| 56 | tmpFolderLocation := "" |
nothing calls this directly
no test coverage detected