aboutsummaryrefslogtreecommitdiff
path: root/tests/cfg-link.testscript
blob: 6d98f03d4e8d1a8d869b794c16da393a05d9fc93 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# file      : tests/cfg-link.testscript
# license   : MIT; see accompanying LICENSE file

.include common.testscript

cfg_create += 2>!
cfg_info   += --link

uuid1 = '18f48b4b-b5d9-4712-b98c-1930df1c4228'
uuid2 = '28f48b4b-b5d9-4712-b98c-1930df1c4228'
uuid3 = '38f48b4b-b5d9-4712-b98c-1930df1c4228'

+$cfg_create -d cfg1 --name 'main'   --uuid "$uuid1" &cfg1/***
+$cfg_create -d cfg2 --name 'shared' --uuid "$uuid2" &cfg2/***

clone_cfgs = cp -r ../cfg1 ../cfg2 ./

sp = ' '

: self
:
{
  $cfg_create -d cfg1 --uuid "$uuid1" &cfg1/***;

  $* -d cfg1 cfg1 2>>/"EOE" != 0
    error: linking configuration $~/cfg1/ with itself
      info: uuid: $uuid1
    EOE
}

: same-name
:
{
  $cfg_create -d cfg1 --name 'main'   &cfg1/***;
  $cfg_create -d cfg2 --name 'shared' &cfg2/***;

  $* -d cfg1 cfg2 --name 'main' 2>>/"EOE" != 0
    error: linking configuration $~/cfg2/ using current configuration name 'main'
      info: consider specifying alternative name with --name
    EOE
}

: basic
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>>/"EOE";
    linked with configuration $~/cfg2/
      uuid: $uuid2
      type: target
      name: shared
      id:   1
    EOE

  $cfg_info -d cfg1 >>/"EOO";
    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: main

    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared
    EOO

  $cfg_info -d cfg2 --backlink >>/"EOO";
    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared

    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: main
    EOO

  # While at it, test that an implicit link is unnamed.
  #
  mv cfg1 cfg1.tmp;

  $cfg_info -d cfg2 --dangling >>/"EOO"
    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared

    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name:$sp
    EOO
}

: implicit-relink
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  rm -r cfg1/;
  $cfg_create -d cfg1 --name 'foo' --uuid "$uuid1";

  $* -d cfg1 cfg2 2>>/"EOE";
    warning: current configuration $~/cfg1/ is already implicitly linked with $~/cfg2/
    linked with configuration $~/cfg2/
      uuid: $uuid2
      type: target
      name: shared
      id:   1
    EOE

  $cfg_info -d cfg1 >>/"EOO"
    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: foo

    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared
    EOO
}

: turn-implicit-explicit
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  $* -d cfg2 cfg1 2>>/"EOE";
    linked with configuration $~/cfg1/
      uuid: $uuid1
      type: target
      name: main
      id:   1
    EOE

  $cfg_info -d cfg2 >>/"EOO";
    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared

    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: main
    EOO

  $cfg_info -d cfg1 >>/"EOO";
    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: main

    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared
    EOO

  # While at it, test that relink attempt is reported.
  #
  $* -d cfg2 cfg1 2>>/"EOE" != 0
    error: configuration with uuid $uuid1 is already linked as ../cfg1/
    EOE
}

: uuid-clash
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  $* -d cfg1 cfg2 2>>/"EOE" != 0
    error: configuration with uuid $uuid2 is already linked as ../cfg2/
    EOE
}

: path-clash
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  mv cfg2 cfg2.tmp;
  $cfg_create -d cfg2 --name 'shared' --uuid "$uuid3" &cfg2/***;

  $* -d cfg1 cfg2 2>>/"EOE" != 0
    error: configuration with path $~/cfg2/ is already linked
    EOE
}

: name-clash
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  $cfg_create -d cfg3 --name 'shared' --uuid "$uuid3" &cfg3/***;

  $* -d cfg1 cfg3 --name 'shared' 2>>/"EOE" != 0;
    error: configuration with name shared is already linked as ../cfg2/
      info: consider specifying alternative name with --name
    EOE

  $* -d cfg1 cfg3 2>>/"EOE"
    warning: configuration with name shared is already linked as ../cfg2/, linking as unnamed
    linked with configuration $~/cfg3/
      uuid: $uuid3
      type: target
      id:   2
    EOE
}

: implicit-link-path-clash
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;
  $* -d cfg2 cfg1 2>!;

  mv cfg1 cfg1.tmp;
  $cfg_create -d cfg1 --name 'main' --uuid "$uuid3" &cfg1/***;

  $* -d cfg1 cfg2 2>>/"EOE" != 0
    error: current configuration $~/cfg1/ is already linked with $~/cfg2/
    EOE
}

: uuid-mismatch
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  mv cfg2 cfg2.tmp;

  $cfg_create -d cfg2 --name 'shared' --uuid "$uuid3";

  $cfg_info -d cfg1 >- 2>>/"EOE" != 0;
    error: configuration cfg2/ uuid mismatch
      info: uuid $uuid3
      info: linked with cfg1/ as $uuid2
    EOE

  rm -r cfg2;
  mv cfg2.tmp cfg2;

  $cfg_info -d cfg1 >>/"EOO"
    path: $~/cfg1/
    uuid: $uuid1
    type: target
    name: main

    path: $~/cfg2/
    uuid: $uuid2
    type: target
    name: shared
    EOO
}

: type-mismatch
:
{
  $clone_cfgs;

  $* -d cfg1 cfg2 2>!;

  rm -r cfg2;

  $cfg_create -d cfg2 --name 'shared' --uuid "$uuid2" --type 'shared';

  $cfg_info -d cfg1 >- 2>>/"EOE" != 0
    error: configuration cfg2/ type mismatch
      info: type shared
      info: linked with cfg1/ as target
    EOE
}