ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
53
services/minecraft/store-tests.fsx
Normal file
53
services/minecraft/store-tests.fsx
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#load "store.fsx"
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Net
|
||||
open System.Text
|
||||
open System.Threading.Tasks
|
||||
open Amazon.Runtime
|
||||
open Amazon.S3
|
||||
open Amazon.S3.Model
|
||||
open Bootstrap
|
||||
|
||||
let check condition message = if not condition then failwith message
|
||||
|
||||
type MemoryStore() =
|
||||
inherit AmazonS3Client(BasicAWSCredentials("fixture", "synthetic-secret"), AmazonS3Config(ServiceURL = "http://127.0.0.1", AuthenticationRegion = "us-east-1"))
|
||||
let mutable reads = 0
|
||||
let mutable key = ""
|
||||
member _.Reads = reads
|
||||
member _.Key = key
|
||||
override _.GetObjectAsync(request: GetObjectRequest, _) =
|
||||
reads <- reads + 1
|
||||
key <- request.Key
|
||||
let bytes = Encoding.UTF8.GetBytes(if request.Key.EndsWith ".sha256" then "inventory" else "synthetic artifact")
|
||||
Task.FromResult(new GetObjectResponse(HttpStatusCode = HttpStatusCode.OK, ResponseStream = new MemoryStream(bytes)))
|
||||
|
||||
let root = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))
|
||||
Directory.CreateDirectory root |> ignore
|
||||
|
||||
try
|
||||
use client = new MemoryStore()
|
||||
check (Store.manifest client "mods.sha256" = "inventory") "inventory"
|
||||
let sample = Path.Combine(root, "sample")
|
||||
File.WriteAllText(sample, "synthetic artifact")
|
||||
let expected = digest sample
|
||||
let path = Path.Combine(root, "object")
|
||||
Store.fetch client "mods/a.jar" expected path
|
||||
check (digest path = expected) "download"
|
||||
check (client.Key = "minecraft/mods/a.jar") "pack key"
|
||||
Store.fetch client "mods/a.jar" expected path
|
||||
check (client.Reads = 2) "cache hit"
|
||||
let rejected =
|
||||
try
|
||||
Store.fetch client "mods/a.jar" (String.replicate 64 "0") path
|
||||
false
|
||||
with :? InvalidOperationException -> true
|
||||
check rejected "wrong checksum accepted"
|
||||
check (digest path = expected) "failed download replaced cache"
|
||||
Store.saltatory client expected (Path.Combine(root, "saltatory.jar"))
|
||||
check (client.Key = "saltatory/" + expected + ".jar") "saltatory key"
|
||||
printfn "store tests passed"
|
||||
finally
|
||||
Directory.Delete(root, true)
|
||||
Loading…
Reference in a new issue