Skip to content

Commit

Permalink
separate package cache in preview and release
Browse files Browse the repository at this point in the history
  • Loading branch information
caroott committed Mar 4, 2024
1 parent fa8a949 commit 2ff0ed6
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/ARCValidationPackages/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Config = {
Config.create(
packageIndex = GitHubAPI.getPackageIndex(?Token = Token),
indexLastUpdated = System.DateTimeOffset.Now,
packageCacheFolder = defaultArg CacheFolder (Defaults.PACKAGE_CACHE_FOLDER()),
packageCacheFolder = defaultArg CacheFolder (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW()),
configFilePath = defaultArg ConfigPath (Defaults.CONFIG_FILE_PATH())
)
static member indexContainsPackages (packageName: string) (config: Config) =
Expand Down
23 changes: 18 additions & 5 deletions src/ARCValidationPackages/Defaults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module Defaults =

let [<Literal>] CONFIG_FILE_NAME = "validation-packages-config.json"

let [<Literal>] PACKAGE_CACHE_FOLDER_NAME = "package-cache"
let [<Literal>] PACKAGE_CACHE_FOLDER_NAME_PREVIEW = "package-cache-preview"

let [<Literal>] PACKAGE_CACHE_FOLDER_NAME_RELEASE = "package-cache-release"

let [<Literal>] PACKAGE_CACHE_FILE_NAME = "validation-packages-cache.json"

Expand All @@ -44,15 +46,26 @@ module Defaults =
Path.Combine(CONFIG_FOLDER(), CONFIG_FILE_NAME)
.Replace("\\", "/")

let PACKAGE_CACHE_FOLDER () =
let PACKAGE_CACHE_FOLDER_PREVIEW () =
let path =
Path.Combine(CONFIG_FOLDER(), PACKAGE_CACHE_FOLDER_NAME_PREVIEW)
.Replace("\\", "/")
Directory.CreateDirectory(path) |> ignore
path

let PACKAGE_CACHE_FOLDER_RELEASE () =
let path =
Path.Combine(CONFIG_FOLDER(), PACKAGE_CACHE_FOLDER_NAME)
Path.Combine(CONFIG_FOLDER(), PACKAGE_CACHE_FOLDER_NAME_RELEASE)
.Replace("\\", "/")
Directory.CreateDirectory(path) |> ignore
path

let PACKAGE_CACHE_FILE_PATH () =
Path.Combine(PACKAGE_CACHE_FOLDER(), PACKAGE_CACHE_FILE_NAME)
let PACKAGE_CACHE_FILE_PATH_PREVIEW () =
Path.Combine(PACKAGE_CACHE_FOLDER_PREVIEW(), PACKAGE_CACHE_FILE_NAME)
.Replace("\\", "/")

let PACKAGE_CACHE_FILE_PATH_RELEASE () =
Path.Combine(PACKAGE_CACHE_FOLDER_RELEASE(), PACKAGE_CACHE_FILE_NAME)
.Replace("\\", "/")

let SERIALIZATION_OPTIONS = JsonSerializerOptions(WriteIndented = true)
Expand Down
4 changes: 2 additions & 2 deletions src/ARCValidationPackages/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type CachedValidationPackage =
/// <param name="packageIndex">The input package index entry</param>
/// <param name="Date">Optional. The date to set the CacheDate to. Defaults to the current date.</param>
static member ofPackageIndex (packageIndex: ValidationPackageIndex, ?Date: System.DateTimeOffset, ?CacheFolder: string) =
let path = defaultArg CacheFolder (Defaults.PACKAGE_CACHE_FOLDER())
let path = defaultArg CacheFolder (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
CachedValidationPackage.create(
fileName = packageIndex.FileName,
cacheDate = (defaultArg Date System.DateTimeOffset.Now),
Expand All @@ -56,7 +56,7 @@ type CachedValidationPackage =
/// <param name="Date"></param>
/// <param name="Path"></param>
static member ofPackageName (packageName: string, ?Date: System.DateTimeOffset, ?Path: string) =
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FOLDER())
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
CachedValidationPackage.create(
fileName = packageName,
cacheDate = (defaultArg Date System.DateTimeOffset.Now),
Expand Down
8 changes: 4 additions & 4 deletions src/ARCValidationPackages/PackageCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ type PackageCache =
cache

static member exists (?Path: string) =
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FILE_PATH())
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FILE_PATH_PREVIEW())
File.Exists(path)

static member read (?Path: string) =
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FILE_PATH())
let path = defaultArg Path (Defaults.PACKAGE_CACHE_FILE_PATH_PREVIEW())
path
|> File.ReadAllText
|> fun jsonString -> JsonSerializer.Deserialize<PackageCache>(jsonString, Defaults.SERIALIZATION_OPTIONS)

static member get (?Folder: string, ?FileName: string) =
let fileName = defaultArg FileName (Defaults.PACKAGE_CACHE_FILE_NAME)
let folder = defaultArg Folder (Defaults.PACKAGE_CACHE_FOLDER())
let folder = defaultArg Folder (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
let path = Path.Combine(folder, fileName)
if PackageCache.exists(path) then
PackageCache.read(path)
Expand All @@ -167,7 +167,7 @@ type PackageCache =
static member write (?Folder: string, ?FileName: string) =
fun (cache: PackageCache) ->
let fileName = defaultArg FileName (Defaults.PACKAGE_CACHE_FILE_NAME)
let folder = defaultArg Folder (Defaults.PACKAGE_CACHE_FOLDER())
let folder = defaultArg Folder (Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
let path = Path.Combine(folder, fileName)
System.IO.FileInfo(path).Directory.Create(); // ensures directory exists
JsonSerializer.Serialize(cache, Defaults.SERIALIZATION_OPTIONS)
Expand Down
1 change: 1 addition & 0 deletions src/ARCValidationPackages/TopLevelAPI.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ARCValidationPackages
open System.IO
open AVPRIndex
open AVPRIndex.Domain

type APIError =
Expand Down
4 changes: 2 additions & 2 deletions tests/ARCValidationPackages.Tests/ConfigTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let ``Config tests`` =
packageIndex = testPackageIndex,
indexLastUpdated = testDate1,
configFilePath = Defaults.CONFIG_FILE_PATH(),
packageCacheFolder = Defaults.PACKAGE_CACHE_FOLDER()
packageCacheFolder = Defaults.PACKAGE_CACHE_FOLDER_PREVIEW()
)

test "config file path is correct" {
Expand All @@ -31,7 +31,7 @@ let ``Config tests`` =
test "package cache folder is correct" {
Expect.equal
(testConfig.PackageCacheFolder)
expected_package_cache_folder_path
expected_package_cache_folder_path_preview
"package cache folder path is not correct"
}
test "config folder path is correct" {
Expand Down
10 changes: 5 additions & 5 deletions tests/ARCValidationPackages.Tests/DefaultsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ let ``Defaults tests`` =
}
test "package cache folder path is correct" {
Expect.equal
(Defaults.PACKAGE_CACHE_FOLDER())
expected_package_cache_folder_path
(Defaults.PACKAGE_CACHE_FOLDER_PREVIEW())
expected_package_cache_folder_path_preview
"package cache folder path is not correct"
}
test "package cache folder path exists" {
Expect.isTrue
(Directory.Exists(expected_package_cache_folder_path))
(Directory.Exists(expected_package_cache_folder_path_preview))
"package cache folder path does not exist"
}
test "package cache file path is correct" {
Expect.equal
(Defaults.PACKAGE_CACHE_FILE_PATH())
expected_package_cache_file_path
(Defaults.PACKAGE_CACHE_FILE_PATH_PREVIEW())
expected_package_cache_file_path_preview
"config file path is not correct"
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ARCValidationPackages.Tests/PackageCacheTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let tests =
test "can write json" {
deleteDefaultPackageCache() // make sure any cached file is deleted before testing that it can be written
testPackageCache1 |> PackageCache.write()
Expect.isTrue (File.Exists(expected_package_cache_file_path)) "package cache file was not created"
Expect.isTrue (File.Exists(expected_package_cache_file_path_preview)) "package cache file was not created"
} |> testSequenced

test "can read json" {
Expand Down
6 changes: 3 additions & 3 deletions tests/ARCValidationPackages.Tests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ let testValidationPackage1 =
CachedValidationPackage.create(
"test@1.0.0.fsx",
testDate1,
(Path.Combine(expected_package_cache_folder_path, "test@1.0.0.fsx").Replace("\\","/")),
(Path.Combine(expected_package_cache_folder_path_preview, "test@1.0.0.fsx").Replace("\\","/")),
ValidationPackageMetadata.create("test", "this package is here for testing purposes only.", "this package is here for testing purposes only.", 1, 0, 0)
)

let testValidationPackage2 =
CachedValidationPackage.create(
"test@1.0.0.fsx",
testDate2,
(Path.Combine(expected_package_cache_folder_path, "test@1.0.0.fsx").Replace("\\","/")),
(Path.Combine(expected_package_cache_folder_path_preview, "test@1.0.0.fsx").Replace("\\","/")),
ValidationPackageMetadata.create("test", "this package is here for testing purposes only.", "this package is here for testing purposes only.", 1, 0, 0)
)

let testValidationPackage3FullMetadata =
CachedValidationPackage.create(
"test@3.0.0.fsx",
testDate3,
(Path.Combine(expected_package_cache_folder_path, "test@3.0.0.fsx").Replace("\\","/")),
(Path.Combine(expected_package_cache_folder_path_preview, "test@3.0.0.fsx").Replace("\\","/")),
ValidationPackageMetadata.create(
"test",
"this package is here for testing purposes only.",
Expand Down
2 changes: 1 addition & 1 deletion tests/ARCValidationPackages.Tests/TopLevelAPITests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let ``Toplevel API tests`` =

"Fresh package cache folder",
fun (freshConfig, _) ->
Expect.equal freshConfig.PackageCacheFolder expected_package_cache_folder_path "package cache folder path is not correct"
Expect.equal freshConfig.PackageCacheFolder expected_package_cache_folder_path_preview "package cache folder path is not correct"

"Fresh config package index contains packages",
fun (freshConfig, _) ->
Expand Down
14 changes: 9 additions & 5 deletions tests/Common/TestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ module TestUtils =
let expected_config_folder_path = Path.Combine(application_data_path, "nfdi4plants/arc-validate").Replace("\\", "/")
let expected_config_file_path = Path.Combine(expected_config_folder_path, "validation-packages-config.json").Replace("\\", "/")

let expected_package_cache_folder_path = Path.Combine(expected_config_folder_path, "package-cache").Replace("\\", "/")
let expected_package_cache_file_path = Path.Combine(expected_package_cache_folder_path, "validation-packages-cache.json").Replace("\\", "/")
let expected_package_cache_folder_path_preview = Path.Combine(expected_config_folder_path, "package-cache-preview").Replace("\\", "/")
let expected_package_cache_file_path_preview = Path.Combine(expected_package_cache_folder_path_preview, "validation-packages-cache.json").Replace("\\", "/")

let expected_package_cache_folder_path_release = Path.Combine(expected_config_folder_path, "package-cache-release").Replace("\\", "/")
let expected_package_cache_file_path_release = Path.Combine(expected_package_cache_folder_path_release, "validation-packages-cache.json").Replace("\\", "/")


let runTool (tool: string) (args: string []) =
CreateProcess.fromRawCommand tool args
Expand All @@ -32,13 +36,13 @@ module TestUtils =

// remove any existing config folder for running tests
if Directory.Exists(expected_config_folder_path) then Directory.Delete(expected_config_folder_path, true)
if Directory.Exists(expected_package_cache_folder_path) then Directory.Delete(expected_package_cache_folder_path, true)
if Directory.Exists(expected_package_cache_folder_path_preview) then Directory.Delete(expected_package_cache_folder_path_preview, true)
// ensure that these file do not exist before running tests
if File.Exists(expected_config_file_path) then File.Delete(expected_config_file_path)
if File.Exists(expected_package_cache_file_path) then File.Delete(expected_package_cache_file_path)
if File.Exists(expected_package_cache_file_path_preview) then File.Delete(expected_package_cache_file_path_preview)

let deleteDefaultPackageCache() =
if File.Exists(expected_package_cache_file_path) then File.Delete(expected_package_cache_file_path)
if File.Exists(expected_package_cache_file_path_preview) then File.Delete(expected_package_cache_file_path_preview)

let deleteDefaultConfig() =
if File.Exists(expected_config_file_path) then File.Delete(expected_config_file_path)
Expand Down
Loading

0 comments on commit 2ff0ed6

Please sign in to comment.