aboutsummaryrefslogtreecommitdiff
path: root/tests/submit/submit-pub.testscript
blob: c5d435fde2440aa7a3b39fed785b6e1d5b23dbb5 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# file      : tests/submit/submit-pub.testscript
# license   : MIT; see accompanying LICENSE file

.include data.testscript

user=$getenv("USER")

# Disable tests if the password-less sudo is not enabled for the user.
#
+if! sudo -u "$user" --non-interactive echo 'test' >'test'
  exit
end

root_rep=$~/pkg-1

+mkdir -p $root_rep/1
+echo ": 1" >=$root_rep/1/repositories.manifest
+bpkg rep-create $root_rep/1 2>! &$root_rep/1/packages.manifest

clone_root_rep = cp --no-cleanup -r $root_rep ./ &pkg-1/*** &?pkg.lock

: args
{
  : none
  :
  $* 2>>~%EOE% != 0
  %\[.+\] \[brep:error\] \[ref \] \[brep-submit-pub\]: usage: .+brep-submit-pub \[<options>\] \[<loader-path> <loader-options>\] <repo> <dir>%
  EOE

  : few
  :
  $* 2>>~%EOE% != 0
  %\[.+\] \[brep:error\] \[ref \] \[brep-submit-pub\]: usage: .+brep-submit-pub \[<options>\] \[<loader-path> <loader-options>\] <repo> <dir>%
  EOE

  : repo-not-exist
  :
  $* $~/repo $~/dir 2>>~%EOE% != 0
    %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-pub\]: '.+repo' does not exist or is not a symlink%
    EOE

  : dir-not-exist
  :
  {
    $clone_root_rep;
    ln -s pkg-1 pkg;
    $* $~/pkg $~/dir 2>>~%EOE% != 0
      %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-pub\]: '.+dir' does not exist or is not a directory%
      EOE
  }
}

: success
:
{
  test.options += --user "$user"

  : simulate
  :
  {
    $clone_root_data;
    echo 'simulate: success' >+$data_dir/request.manifest;

    $clone_root_rep;
    ln -s pkg-1 pkg;

    $* $~/pkg $~/$data_dir >>"EOO";
      : 1
      status: 200
      message: package is published: libhello/0.1.0
      reference: $checksum
      EOO

    test -d $data_dir != 0
  }

  : for-real
  :
  : Here we also create the package revision which is expected to be removed
  : by the handler.
  :
  {
    $clone_root_data;
    $clone_root_rep;
    ln -s pkg-1 pkg;

    # Initial submission.
    #
    $* $~/pkg $~/$data_dir &!pkg-1/*** &pkg-*/*** >>"EOO";
      : 1
      status: 200
      message: package is published: libhello/0.1.0
      reference: $checksum
      EOO

    test -f pkg/1/hello/libhello-0.1.0.tar.gz;

    # While at it, test the duplicate submission.
    #
    $clone_root_data_clean;

    $* $~/pkg $~/$data_dir >>"EOO";
      : 1
      status: 422
      message: duplicate submission
      reference: $checksum
      EOO

    test -f pkg/1/hello/libhello-0.1.0.tar.gz;

    # Revision submission.
    #
    # Here we test that the handler removes the previous revision.
    #
    tar -xf $~/$data_dir/libhello-0.1.0.tar.gz;
    sed -i -e 's/(version: 0.1.0)/\1+1/' libhello-0.1.0/manifest;
    mv libhello-0.1.0 libhello-0.1.0+1;
    tar cfz $~/$data_dir/libhello-0.1.0+1.tar.gz libhello-0.1.0+1;
    rm -r libhello-0.1.0+1;
    rm $~/$data_dir/libhello-0.1.0.tar.gz;
    sed -i -e 's/(archive: libhello-0.1.0)(.tar.gz)/\1+1\2/' $data_dir/request.manifest;

    $* $~/pkg $~/$data_dir >>"EOO";
      : 1
      status: 200
      message: package is published: libhello/0.1.0+1
      reference: $checksum
      EOO

    test -f pkg/1/hello/libhello-0.1.0.tar.gz == 1;
    test -f pkg/1/hello/libhello-0.1.0+1.tar.gz;

    # While at it, test the older revision submission.
    #
    $clone_root_data_clean;

    $* $~/pkg $~/$data_dir >>"EOO";
      : 1
      status: 422
      message: newer revision libhello/0.1.0+1 is present
      reference: $checksum
      EOO

    test -f pkg/1/hello/libhello-0.1.0+1.tar.gz
  }

  : result-url
  :
  {
    $clone_root_data;
    $clone_root_rep;
    ln -s pkg-1 pkg;

    test.options += --result-url 'https://example.com/';

    $* $~/pkg $~/$data_dir &!pkg-1/*** &pkg-*/*** >>"EOO"
      : 1
      status: 200
      message: package is published: https://example.com/libhello/0.1.0
      reference: $checksum
      EOO
  }
}

: failure
:
{
  test.options += --user "$user"

  : invalid-package
  :
  : Here we remove repositories.manifest to make sure that the bpkg-rep-create
  : failure ends up with a proper response.
  :
  {
    $clone_root_data_clean;
    $clone_root_rep;
    ln -s pkg-1 pkg;

    rm pkg/1/repositories.manifest;

    $* $~/brep-loader $~/pkg $~/$data_dir >>~"%EOO%"
      : 1
      status: 400
      message:\\
      submitted archive is not a valid package
      %.+
      \\
      reference: $checksum
      EOO
  }

  : not-loadable
  :
  : Here we specify a non-existing brep loader program to make sure that the
  : brep database load failure ends up with a proper response.
  :
  {
    $clone_root_data_clean;
    $clone_root_rep;
    ln -s pkg-1 pkg;

    $* $~/brep-loader $~/pkg $~/$data_dir >>~"%EOO%"
      : 1
      status: 400
      message:\\
      unable to add package to repository
      %.+
      \\
      reference: $checksum
      EOO
  }
}