aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/deploy.lux
blob: 86f3e0dbb907929acbc5f3b6f0acac5fc0fa8bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    ["." monad (#+ do)]]
   [control
    ["." try (#+ Try) ("#\." functor)]
    ["." exception]
    [concurrency
     ["." promise (#+ Promise)]]
    [security
     ["!" capability]]
    [parser
     ["." environment (#+ Environment)]]]
   [data
    ["." maybe]
    ["." binary]
    ["." text ("#\." equivalence)
     ["%" format (#+ format)]
     ["." encoding]]
    ["." format #_
     ["#" binary]
     ["." tar]
     ["." xml]]
    [collection
     ["." set (#+ Set)]
     ["." dictionary (#+ Dictionary)]]]
   [math
    ["." random (#+ Random)]]
   [world
    ["." file (#+ Path File)]
    ["." program (#+ Program)]]]
  [program
   [compositor
    ["." export]]]
  [//
   ["@." version]
   [//
    ["@." profile]
    ["@." repository]]]
  {#program
   ["." /
    ["/#" // #_
     ["#." clean]
     ["/#" // #_
      ["#" profile]
      ["#." action]
      ["#." pom]
      ["#." local]
      ["#." hash]
      ["#." repository (#+ Repository)
       [identity (#+ Identity)]]
      ["#." artifact (#+ Artifact)
       ["#/." extension]]]]]})

(def: (make-sources! fs sources)
  (-> (file.System Promise) (Set Path) (Promise (Try Any)))
  (loop [sources (set.to-list sources)]
    (case sources
      #.Nil
      (|> []
          (\ try.monad wrap)
          (\ promise.monad wrap))
      
      (#.Cons head tail)
      (do (try.with promise.monad)
        [_ (: (Promise (Try Path))
              (file.make-directories promise.monad fs head))
         _ (: (Promise (Try (File Promise)))
              (file.get-file promise.monad fs (format head (\ fs separator) head ".lux")))]
        (recur tail)))))

(def: (execute! program repository fs artifact profile)
  (-> (Program Promise) (Repository Promise) (file.System Promise)
      Artifact ///.Profile
      (Promise (Try Text)))
  (do promise.monad
    [home (\ program home [])]
    (do ///action.monad
      [#let [console (@version.echo "")]
       _ (..make-sources! fs (get@ #///.sources profile))
       _ (: (Promise (Try Path))
            (file.make-directories promise.monad fs (///local.repository fs home)))
       _ (/.do! console repository fs artifact profile)]
      (!.use (\ console read-line) []))))

(def: #export test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [[artifact expected-pom profile]
         (random.one (function (_ profile)
                       (do maybe.monad
                         [artifact (get@ #///.identity profile)
                          expected-pom (try.to-maybe (///pom.write profile))]
                         (wrap [artifact expected-pom profile])))
                     @profile.random)
         
         home (random.ascii/alpha 5)
         working-directory (random.ascii/alpha 5)
         #let [repository (///repository.mock @repository.simulation
                                              @repository.empty)
               fs (file.mock (\ file.default separator))
               program (program.async (program.mock environment.empty home working-directory))]]
        (wrap (do {! promise.monad}
                [verdict (do {! ///action.monad}
                           [logging (..execute! program repository fs artifact profile)
                            expected-library (|> profile
                                                 (get@ #///.sources)
                                                 set.to-list
                                                 (export.library fs)
                                                 (\ ! map (format.run tar.writer)))

                            actual-pom (\ repository download (///repository.uri artifact ///artifact/extension.pom))
                            actual-library (\ repository download (///repository.uri artifact ///artifact/extension.lux-library))
                            actual-sha-1 (\ repository download (///repository.uri artifact (format ///artifact/extension.lux-library ///artifact/extension.sha-1)))
                            actual-md5 (\ repository download (///repository.uri artifact (format ///artifact/extension.lux-library ///artifact/extension.md5)))

                            #let [deployed-library!
                                  (\ binary.equivalence =
                                     expected-library
                                     actual-library)

                                  deployed-pom!
                                  (\ binary.equivalence =
                                     (|> expected-pom (\ xml.codec encode) (\ encoding.utf8 encode))
                                     actual-pom)

                                  deployed-sha-1!
                                  (\ binary.equivalence =
                                     (///hash.data (///hash.sha-1 expected-library))
                                     actual-sha-1)

                                  deployed-md5!
                                  (\ binary.equivalence =
                                     (///hash.data (///hash.md5 expected-library))
                                     actual-md5)]]
                           (wrap (and (text\= //clean.success logging)
                                      deployed-library!
                                      deployed-pom!
                                      deployed-sha-1!
                                      deployed-md5!)))]
                (_.cover' [/.do!]
                          (try.default false verdict)))))))