aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/deploy.lux
blob: 77af481263d3606f1df602fd1ac2e5b5ede1d4db (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
(.module:
  [library
   [lux "*"
    ["_" test {"+" [Test]}]
    [abstract
     [monad {"+" [do]}]]
    [control
     ["." maybe]
     ["." try {"+" [Try]}]
     [concurrency
      ["." async {"+" [Async]}]]
     [parser
      ["." environment]]]
    [data
     ["." binary ("#\." equivalence)]
     ["." text ("#\." equivalence)
      ["%" format {"+" [format]}]
      [encoding
       ["." utf8]]]
     ["." format "_"
      ["#" binary]
      ["." tar]
      ["." xml]]
     [collection
      ["." set]]]
    [math
     ["." random]]
    [world
     ["." file]
     ["." program {"+" [Program]}]]]]
  [program
   [compositor
    ["." export]]]
  [//
   ["$." install]
   ["$." version]
   [//
    ["$." profile]
    ["$." repository]]]
  [\\program
   ["." /
    ["//#" /// "_"
     ["#" profile]
     ["#." action]
     ["#." pom]
     ["#." hash]
     ["#." repository {"+" [Repository]}
      ["#/." remote]]
     ["#." artifact {"+" [Artifact]}
      ["#/." extension]]]]])

(def: (execute! program repository fs artifact profile)
  (-> (Program Async) (Repository Async) (file.System Async)
      Artifact ///.Profile
      (Async (Try Text)))
  (do ///action.monad
    [.let [console ($version.echo "")]
     _ ($install.make_sources! fs (value@ #///.sources profile))
     _ (/.do! console repository fs artifact profile)]
    (\ console read_line [])))

(def: .public test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [[artifact expected_pom profile]
         (random.one (function (_ profile)
                       (do maybe.monad
                         [artifact (value@ #///.identity profile)
                          expected_pom (try.maybe (///pom.write profile))]
                         (in [artifact expected_pom profile])))
                     $profile.random)
         
         home (random.ascii/alpha 5)
         working_directory (random.ascii/alpha 5)
         .let [repository (///repository.mock $repository.mock
                                              $repository.empty)
               fs (file.mock (\ file.default separator))
               program (program.async (program.mock environment.empty home working_directory))]]
        (in (do {! async.monad}
              [verdict (do {! ///action.monad}
                         [logging (..execute! program repository fs artifact profile)
                          expected_library (|> profile
                                               (value@ #///.sources)
                                               set.list
                                               (export.library fs)
                                               (\ ! each (format.result tar.writer)))

                          actual_pom (\ repository download (///repository/remote.uri (value@ #///artifact.version artifact) artifact ///artifact/extension.pom))
                          actual_library (\ repository download (///repository/remote.uri (value@ #///artifact.version artifact) artifact ///artifact/extension.lux_library))
                          actual_sha-1 (\ repository download (///repository/remote.uri (value@ #///artifact.version artifact) artifact (format ///artifact/extension.lux_library ///artifact/extension.sha-1)))
                          actual_sha-1 (\ async.monad in
                                          (do try.monad
                                            [actual_sha-1 (\ utf8.codec decoded actual_sha-1)]
                                            (\ ///hash.sha-1_codec decoded actual_sha-1)))
                          actual_md5 (\ repository download (///repository/remote.uri (value@ #///artifact.version artifact) artifact (format ///artifact/extension.lux_library ///artifact/extension.md5)))
                          actual_md5 (\ async.monad in
                                        (do try.monad
                                          [actual_md5 (\ utf8.codec decoded actual_md5)]
                                          (\ ///hash.md5_codec decoded actual_md5)))

                          .let [succeeded!
                                (text\= /.success logging)

                                deployed_library!
                                (binary\= expected_library
                                          actual_library)

                                deployed_pom!
                                (binary\= (|> expected_pom (\ xml.codec encoded) (\ utf8.codec encoded))
                                          actual_pom)

                                deployed_sha-1!
                                (\ ///hash.equivalence =
                                   (///hash.sha-1 expected_library)
                                   actual_sha-1)

                                deployed_md5!
                                (\ ///hash.equivalence =
                                   (///hash.md5 expected_library)
                                   actual_md5)]]
                         (in (and succeeded!
                                  deployed_library!
                                  deployed_pom!
                                  deployed_sha-1!
                                  deployed_md5!)))]
              (_.cover' [/.do! /.success]
                        (try.else false verdict)))))))