-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save only the relative path of the filename for StaticDirStorage
#1990
Merged
Merged
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f68f5b6
Save only the relative path of the filename for `StaticDirStorage`
amitaibu b13c798
Merge branch 'master' into amitaibu-patch-5
amitaibu 6e0db34
Adapt createTemporaryDownloadUrlFromPathWithExpiredAt
amitaibu d5865c4
Change slash logic
amitaibu b9ced44
Start adding tests
amitaibu 73c2074
Use newControllerContext
amitaibu 6702d3e
Start fix tests
amitaibu 2aa73c0
More fixes
amitaibu ac3f57f
Copy from another test
amitaibu 5a59025
Merge branch 'master' into amitaibu-patch-5
amitaibu 04c8a65
Add withFrameworkConfig
amitaibu 600d9fe
Fix compile
amitaibu 2c867f4
Fix tests
amitaibu 311e57d
Fix logic
amitaibu 35af26f
Ignore test folders
amitaibu 8ecb835
Fix tests
amitaibu 1af1f4f
Re-enable all tests
amitaibu 581b748
Remove line break
amitaibu 9fc7bd9
Import cleanups
amitaibu d40ef01
More line breaks
amitaibu ae9767b
Line breaks
amitaibu 4241679
Fix typo
amitaibu adfaf3c
Prefix objectPath with slash
amitaibu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Test.FileStorage.ControllerFunctionsSpec where | ||
|
||
import Test.Hspec | ||
import IHP.Prelude | ||
import IHP.FileStorage.ControllerFunctions | ||
import IHP.Controller.Context | ||
import IHP.FrameworkConfig | ||
import IHP.ModelSupport | ||
import IHP.FileStorage.Types | ||
import System.IO.Temp (withSystemTempDirectory) | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified Data.Text as Text | ||
import Data.Default (def) | ||
import Data.Time.Clock (getCurrentTime, addUTCTime) | ||
import Network.Wai as Wai (defaultRequest) | ||
import Network.Wai.Parse (FileInfo(..)) | ||
import IHP.Controller.RequestContext | ||
|
||
tests :: Spec | ||
tests = describe "IHP.FileStorage.ControllerFunctions" $ do | ||
describe "storeFileWithOptions" $ do | ||
it "returns the objectPath without the baseUrl" $ do | ||
withSystemTempDirectory "ihp-test" $ \tempDir -> do | ||
context <- createControllerContext | ||
let ?context = context | ||
|
||
let fileInfo = FileInfo | ||
{ fileName = "test.txt" | ||
, fileContentType = "text/plain" | ||
, fileContent = "Hello, world!" | ||
} | ||
|
||
result <- storeFile fileInfo "Test.FileStorage.ControllerFunctionsSpec" | ||
|
||
result.url `shouldBe` "Test.FileStorage.ControllerFunctionsSpec/test.txt" | ||
|
||
describe "createTemporaryDownloadUrlFromPathWithExpiredAt" $ do | ||
it "returns baseUrl concatenated with objectPath when objectPath does not start with http:// or https://" $ do | ||
context <- createControllerContext | ||
let ?context = context | ||
let objectPath = "static/test.txt" | ||
temporaryDownloadUrl <- createTemporaryDownloadUrlFromPath objectPath | ||
|
||
temporaryDownloadUrl.url `shouldBe` "http://localhost:8000/static/test.txt" | ||
|
||
it "returns '/' concatenated with objectPath when objectPath starts with 'http://' or 'https://'" $ do | ||
context <- createControllerContext | ||
let ?context = context | ||
let objectPath = "https://example.com/static/test.txt" | ||
temporaryDownloadUrl <- createTemporaryDownloadUrlFromPath objectPath | ||
|
||
temporaryDownloadUrl.url `shouldBe` "https://example.com/static/test.txt" | ||
|
||
createControllerContext = do | ||
let | ||
requestBody = FormBody { params = [], files = [] } | ||
request = Wai.defaultRequest | ||
requestContext = RequestContext { request, respond = error "respond", requestBody, frameworkConfig = error "frameworkConfig" } | ||
let ?requestContext = requestContext | ||
newControllerContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpscholten 👋 I suspect this line, with the
error
, causes the error I get when running the testHow can I make it work? (Copied from here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That GHC error is unrelated to the error call. I just pushed a workaround via 66518de to master (appartently the INLINE triggers the bug in GHC, but chaging that to an optional inline via INLINABLE not triggers the bug). Can you sync with master and then check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think now it hits that
error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
IHP.FrameworkConfig.withFrameworkConfig
to get a framework config object, like this:And then use the frameworkConfig passed to
createControllerContext
instead of theerror
callThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this I get
While trying to figure how to pass a config with the
initStaticDirStorage
(didn't figure yet), I foundaroundAll (withIHPApp WebApplication config) do
Maybe we should use that? (If so, not sure how 😅 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to init the storage here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests passing locally ✌️