|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | + |
| 3 | +module ReadOnly where |
| 4 | + |
| 5 | +import Data.Default.Class (Default(def)) |
| 6 | +import Test.Hspec (Spec, describe, it, shouldBe) |
| 7 | + |
| 8 | +import Crypto.Hash (hash, Digest, SHA256(..)) |
| 9 | +import Data.ByteString (ByteString) |
| 10 | +import System.Nix.StorePath (StorePath, StorePathName) |
| 11 | + |
| 12 | +import qualified Data.HashSet |
| 13 | +import qualified System.Nix.StorePath |
| 14 | + |
| 15 | +import System.Nix.ReadonlyStore |
| 16 | + |
| 17 | +testDigest :: Digest SHA256 |
| 18 | +testDigest = Crypto.Hash.hash @ByteString "testDigest" |
| 19 | + |
| 20 | +testName :: StorePathName |
| 21 | +testName = |
| 22 | + either undefined id |
| 23 | + $ System.Nix.StorePath.makeStorePathName "testFixed" |
| 24 | + |
| 25 | +testPath :: StorePath |
| 26 | +testPath = |
| 27 | + either undefined id |
| 28 | + $ System.Nix.StorePath.parsePathFromText |
| 29 | + def |
| 30 | + "/nix/store/9472ijanf79nlkb5n1yh57s7867p1930-testFixed" |
| 31 | + |
| 32 | +testPath2 :: StorePath |
| 33 | +testPath2 = |
| 34 | + either undefined id |
| 35 | + $ System.Nix.StorePath.parsePathFromText |
| 36 | + def |
| 37 | + "/nix/store/iali40m5597kikibjxw8cx1ssxlqnii3-testFixed" |
| 38 | + |
| 39 | +spec_readOnly :: Spec |
| 40 | +spec_readOnly = do |
| 41 | + describe "ReadOnly" $ do |
| 42 | + it "makeStorePath computes correct StorePath" $ |
| 43 | + (pure |
| 44 | + $ makeStorePath |
| 45 | + def |
| 46 | + "test" |
| 47 | + testDigest |
| 48 | + testName |
| 49 | + ) |
| 50 | + `shouldBe` |
| 51 | + System.Nix.StorePath.parsePathFromText |
| 52 | + def |
| 53 | + "/nix/store/iali40m5597kikibjxw8cx1ssxlqnii3-testFixed" |
| 54 | + |
| 55 | + describe "makeTextPath" $ do |
| 56 | + it "computes correct StorePath for empty refs" $ |
| 57 | + (pure |
| 58 | + $ makeTextPath |
| 59 | + def |
| 60 | + testName |
| 61 | + testDigest |
| 62 | + mempty |
| 63 | + ) |
| 64 | + `shouldBe` |
| 65 | + System.Nix.StorePath.parsePathFromText |
| 66 | + def |
| 67 | + "/nix/store/ync87sfmahhaqwnykzwbk31q96drm9vn-testFixed" |
| 68 | + |
| 69 | + it "computes correct StorePath for nonempty refs" $ |
| 70 | + (pure |
| 71 | + $ makeTextPath |
| 72 | + def |
| 73 | + testName |
| 74 | + testDigest |
| 75 | + (Data.HashSet.fromList [ testPath, testPath2 ]) |
| 76 | + ) |
| 77 | + `shouldBe` |
| 78 | + System.Nix.StorePath.parsePathFromText |
| 79 | + def |
| 80 | + "/nix/store/jcvh84zapqndh8hva515d4y41s07n2g8-testFixed" |
| 81 | + |
| 82 | + describe "makeFixedOuputPath" $ do |
| 83 | + it "computes correct StorePath, recursive" $ |
| 84 | + (pure |
| 85 | + $ makeFixedOutputPath |
| 86 | + def |
| 87 | + True |
| 88 | + testDigest |
| 89 | + testName |
| 90 | + ) |
| 91 | + `shouldBe` |
| 92 | + System.Nix.StorePath.parsePathFromText |
| 93 | + def |
| 94 | + "/nix/store/c0cgdqy9i3smyh3as8c4s6fg6nvwdpzy-testFixed" |
| 95 | + |
| 96 | + it "computes correct StorePath, non-recursive" $ |
| 97 | + (pure |
| 98 | + $ makeFixedOutputPath |
| 99 | + def |
| 100 | + False |
| 101 | + testDigest |
| 102 | + testName |
| 103 | + ) |
| 104 | + `shouldBe` |
| 105 | + System.Nix.StorePath.parsePathFromText |
| 106 | + def |
| 107 | + "/nix/store/9472ijanf79nlkb5n1yh57s7867p1930-testFixed" |
| 108 | + |
| 109 | + it "computeStorePathForText computes correct StorePath" $ |
| 110 | + (pure |
| 111 | + $ computeStorePathForText |
| 112 | + def |
| 113 | + testName |
| 114 | + "test" |
| 115 | + (Data.HashSet.fromList [ testPath ]) |
| 116 | + ) |
| 117 | + `shouldBe` |
| 118 | + System.Nix.StorePath.parsePathFromText |
| 119 | + def |
| 120 | + "/nix/store/838lq5qh5a88wsalcjpmj33bcnmpz3pc-testFixed" |
| 121 | + |
| 122 | +-- describe "computeStorePathForForPath" $ do |
| 123 | +-- it "computes correct StorePath" $ |
| 124 | +-- -- "needs IO and a sample directory to add" |
0 commit comments