-
Notifications
You must be signed in to change notification settings - Fork 49
/
t1000-kvs.t
executable file
·1280 lines (1201 loc) · 36.6 KB
/
t1000-kvs.t
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
test_description='Test flux-kvs and kvs in flux session
These are the basic/core flux kvs tests and should be run before
any other tests that require kvs functionality.
'
. `dirname $0`/kvs/kvs-helper.sh
. `dirname $0`/sharness.sh
if test "$TEST_LONG" = "t"; then
test_set_prereq LONGTEST
fi
RPC=${FLUX_BUILD_DIR}/t/request/rpc
# Size the session to one more than the number of cores, minimum of 4
SIZE=$(test_size_large)
test_under_flux ${SIZE} kvs
echo "# $0: flux session size will be ${SIZE}"
DIR=test.a.b
KEY=test.a.b.c
SUBDIR1=test.a.b.d
SUBDIR2=test.a.b.e
#
# Basic put, get, unlink tests
#
test_expect_success 'kvs: integer put' '
flux kvs put --json $KEY.integer=42
'
test_expect_success 'kvs: double put' '
flux kvs put --json $KEY.double=3.14
'
test_expect_success 'kvs: string put' '
flux kvs put --json $KEY.string=foo
'
test_expect_success 'kvs: boolean true put' '
flux kvs put --json $KEY.booleantrue=true
'
test_expect_success 'kvs: boolean false put' '
flux kvs put --json $KEY.booleanfalse=false
'
test_expect_success 'kvs: array put' '
flux kvs put --json $KEY.array="[1,3,5]"
'
test_expect_success 'kvs: object put' '
flux kvs put --json $KEY.object="{\"a\":42}"
'
test_expect_success 'kvs: integer get' '
test_kvs_key $KEY.integer 42
'
test_expect_success 'kvs: double get' '
test_kvs_key $KEY.double 3.140000
'
test_expect_success 'kvs: string get' '
test_kvs_key $KEY.string foo
'
test_expect_success 'kvs: boolean true get' '
test_kvs_key $KEY.booleantrue true
'
test_expect_success 'kvs: boolean false get' '
test_kvs_key $KEY.booleanfalse false
'
test_expect_success 'kvs: array get' '
test_kvs_key $KEY.array "[1, 3, 5]"
'
test_expect_success 'kvs: object get' '
test_kvs_key $KEY.object "{\"a\": 42}"
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.integer &&
test_must_fail flux kvs get --json $KEY.integer
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.double &&
test_must_fail flux kvs get --json $KEY.double
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.string &&
test_must_fail flux kvs get --json $KEY.string
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.booleantrue &&
test_must_fail flux kvs get --json $KEY.booleantrue
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.booleanfalse &&
test_must_fail flux kvs get --json $KEY.booleanfalse
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.array &&
test_must_fail flux kvs get --json $KEY.array
'
test_expect_success 'kvs: unlink works' '
flux kvs unlink $KEY.object &&
test_must_fail flux kvs get --json $KEY.object
'
#
# Basic put, get, unlink tests w/ multiple key inputs
#
test_expect_success 'kvs: put (multiple)' '
flux kvs put --json $KEY.a=42 $KEY.b=3.14 $KEY.c=foo $KEY.d=true $KEY.e="[1,3,5]" $KEY.f="{\"a\":42}"
'
test_expect_success 'kvs: get (multiple)' '
flux kvs get --json $KEY.a $KEY.b $KEY.c $KEY.d $KEY.e $KEY.f >output &&
cat >expected <<EOF &&
42
3.140000
foo
true
[1, 3, 5]
{"a": 42}
EOF
test_cmp expected output
'
test_expect_success 'kvs: unlink (multiple)' '
flux kvs unlink $KEY.a $KEY.b $KEY.c $KEY.d $KEY.e $KEY.f &&
test_must_fail flux kvs get --json $KEY.a &&
test_must_fail flux kvs get --json $KEY.b &&
test_must_fail flux kvs get --json $KEY.c &&
test_must_fail flux kvs get --json $KEY.d &&
test_must_fail flux kvs get --json $KEY.e &&
test_must_fail flux kvs get --json $KEY.f
'
#
# Basic dir tests
#
test_expect_success 'kvs: mkdir' '
flux kvs mkdir $DIR
'
test_expect_success 'kvs: dir success listing empty dir' '
flux kvs dir $DIR | sort >output &&
cat >expected <<EOF &&
EOF
test_cmp expected output
'
test_expect_success 'kvs: mkdir subdir' '
flux kvs mkdir $SUBDIR1
'
test_expect_success 'kvs: dir lists subdir' '
flux kvs dir $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.d.
EOF
test_cmp expected output
'
test_expect_success 'kvs: dir -R lists subdir' '
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.d.
EOF
test_cmp expected output
'
test_expect_success 'kvs: dir -R DIR' '
flux kvs put --json $DIR.a=42 $DIR.b=3.14 $DIR.c=foo $DIR.d=true $DIR.e="[1,3,5]" $DIR.f="{\"a\":42}" &&
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a = 42
$DIR.b = 3.140000
$DIR.c = foo
$DIR.d = true
$DIR.e = [1, 3, 5]
$DIR.f = {"a": 42}
EOF
test_cmp expected output
'
test_expect_success 'kvs: dir -R -d DIR' '
flux kvs dir -R -d $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a
$DIR.b
$DIR.c
$DIR.d
$DIR.e
$DIR.f
EOF
test_cmp expected output
'
test_expect_success 'kvs: kvs dir -R DIR with period end' '
flux kvs dir -R $DIR. | sort >output &&
cat >expected <<EOF &&
$DIR.a = 42
$DIR.b = 3.140000
$DIR.c = foo
$DIR.d = true
$DIR.e = [1, 3, 5]
$DIR.f = {"a": 42}
EOF
test_cmp expected output
'
test_expect_success 'kvs: kvs dir -R -d DIR with period end' '
flux kvs dir -R -d $DIR. | sort >output &&
cat >expected <<EOF &&
$DIR.a
$DIR.b
$DIR.c
$DIR.d
$DIR.e
$DIR.f
EOF
test_cmp expected output
'
test_expect_success 'kvs: kvs dir -R on root "."' '
flux kvs dir -R "." | sort >output &&
cat >expected <<EOF &&
$DIR.a = 42
$DIR.b = 3.140000
$DIR.c = foo
$DIR.d = true
$DIR.e = [1, 3, 5]
$DIR.f = {"a": 42}
EOF
test_cmp expected output
'
test_expect_success 'kvs: kvs dir -R -d on root "."' '
flux kvs dir -R -d "." | sort >output &&
cat >expected <<EOF &&
$DIR.a
$DIR.b
$DIR.c
$DIR.d
$DIR.e
$DIR.f
EOF
test_cmp expected output
'
test_expect_success 'kvs: unlink dir works' '
flux kvs unlink $SUBDIR1 &&
test_must_fail flux kvs dir $SUBDIR1
'
test_expect_success 'kvs: unlink -R works' '
flux kvs unlink -R $DIR &&
test_must_fail flux kvs dir $DIR
'
#
# Basic dir tests (multiple inputs)
#
test_expect_success 'kvs: mkdir (multiple)' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR $SUBDIR1 $SUBDIR2
'
test_expect_success 'kvs: dir multiple subdirs' '
flux kvs dir $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.d.
$DIR.e.
EOF
test_cmp expected output
'
#
# More complex dir tests
#
test_expect_success 'kvs: create a dir with keys and subdir' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=69 &&
flux kvs put --json $DIR.b=70 &&
flux kvs put --json $DIR.c.d.e.f.g=3.14 &&
flux kvs put --json $DIR.d=\"snerg\" &&
flux kvs put --json $DIR.e=true &&
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a = 69
$DIR.b = 70
$DIR.c.d.e.f.g = 3.140000
$DIR.d = snerg
$DIR.e = true
EOF
test_cmp expected output
'
test_expect_success 'kvs: directory with multiple subdirs' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=69 &&
flux kvs put --json $DIR.b.c.d.e.f.g=70 &&
flux kvs put --json $DIR.c.a.b=3.14 &&
flux kvs put --json $DIR.d=\"snerg\" &&
flux kvs put --json $DIR.e=true &&
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a = 69
$DIR.b.c.d.e.f.g = 70
$DIR.c.a.b = 3.140000
$DIR.d = snerg
$DIR.e = true
EOF
test_cmp expected output
'
#
# get corner case tests
#
test_expect_success 'kvs: get a nonexistent key' '
test_must_fail flux kvs get --json NOT.A.KEY
'
test_expect_success 'kvs: try to retrieve a directory as key should fail' '
flux kvs mkdir $DIR.a.b.c &&
test_must_fail flux kvs get --json $DIR
'
#
# put corner case tests
#
test_expect_success 'kvs: put with invalid input' '
test_must_fail flux kvs put --json NOVALUE
'
test_expect_success 'kvs: put key of . fails' '
test_must_fail flux kvs put --json .=1
'
#
# get/put --json corner case tests
#
test_expect_success 'kvs: null is converted to json null' '
flux kvs put --json $DIR.jsonnull=null &&
test_kvs_key $DIR.jsonnull nil
'
test_expect_success 'kvs: quoted null is converted to json string' '
flux kvs put --json $DIR.strnull=\"null\" &&
test_kvs_key $DIR.strnull null
'
#
# dir corner case tests
#
test_empty_directory() {
OUTPUT=`flux kvs dir -R $1 | wc -l` &&
test "x$OUTPUT" = "x0"
}
test_expect_success 'kvs: try to retrieve key as directory should fail' '
flux kvs put --json $DIR.a.b.c.d=42 &&
test_must_fail flux kvs dir $DIR.a.b.c.d
'
test_expect_success 'kvs: empty directory can be created' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR &&
test_empty_directory $DIR
'
#
# unlink corner case tests
#
test_expect_success 'kvs: unlink nonexistent key fails' '
test_must_fail flux kvs unlink NOT.A.KEY
'
test_expect_success 'kvs: unlink nonexistent key with -f does not fail' '
flux kvs unlink -f NOT.A.KEY
'
test_expect_success 'kvs: unlink nonexistent dir with -f does not fail' '
flux kvs unlink -Rf NOT.A.KEY
'
test_expect_success 'kvs: unlink non-empty dir fails' '
flux kvs mkdir $SUBDIR1 $SUBDIR2 &&
test_must_fail flux kvs unlink $DIR
'
test_expect_success 'kvs: unlink -R works' '
flux kvs unlink -R $DIR &&
test_must_fail flux kvs dir $SUBDIR1 &&
test_must_fail flux kvs dir $SUBDIR2 &&
test_must_fail flux kvs dir $DIR
'
test_expect_success 'kvs: empty directory remains after key removed' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=1 &&
test_kvs_key $DIR.a 1 &&
flux kvs unlink $DIR.a &&
test_empty_directory $DIR
'
test_expect_success 'kvs: unlink works on link that points to invalid target' '
flux kvs unlink -Rf $DIR &&
flux kvs link invalid $DIR.link &&
flux kvs unlink $DIR.link
'
test_expect_success 'kvs: unlink works on link that points to invalid namespace' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.foo=1 &&
flux kvs link --target-namespace=invalid $DIR.foo $DIR.link &&
flux kvs unlink $DIR.link
'
test_expect_success 'kvs: unlink works on link with infinite cycle' '
flux kvs unlink -Rf $DIR &&
flux kvs link $DIR.a $DIR.b &&
flux kvs link $DIR.b $DIR.a &&
flux kvs unlink $DIR.a &&
flux kvs unlink $DIR.b &&
test_empty_directory $DIR
'
#
# empty string corner case tests
#
test_expect_success 'kvs: put/get empty string' '
flux kvs unlink -Rf $DIR &&
echo -n "" | flux kvs put --raw $DIR.a=- &&
flux kvs get $DIR.a >output &&
echo -n "" > expected &&
test_cmp output expected
'
test_expect_success 'kvs: dir can read and display empty string' '
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a =
EOF
test_cmp expected output
'
test_expect_success 'kvs: no value with --json is json empty string' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a= &&
flux kvs get --json $DIR.a >output &&
echo "" > expected &&
test_cmp output expected
'
test_expect_success 'kvs: dir can read and display json empty string' '
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a =
EOF
test_cmp expected output
'
#
# get/put --raw tests
#
test_expect_success 'kvs: put/get --raw works with multiple key=val pairs' '
flux kvs unlink -Rf $DIR &&
flux kvs put --raw $DIR.a=xyz $DIR.b=zyx &&
printf "%s" 'xyzzyx' >twovals.expected &&
flux kvs get --raw $DIR.a $DIR.b >twovals.actual &&
test_cmp twovals.expected twovals.actual
'
test_expect_success 'kvs: put --raw a=- reads value from stdin' '
flux kvs unlink -Rf $DIR &&
printf "%s" "abc" | flux kvs put --raw $DIR.a=- &&
printf "%s" "abc" >rawstdin.expected &&
flux kvs get --raw $DIR.a >rawstdin.actual &&
test_cmp rawstdin.expected rawstdin.actual
'
test_expect_success 'kvs: put --raw a=- b=42 works' '
flux kvs unlink -Rf $DIR &&
printf "%s" "abc" | flux kvs put --raw $DIR.a=- $DIR.b=42 &&
printf "%s" "abc42" >rawstdin2.expected &&
flux kvs get --raw $DIR.a $DIR.b >rawstdin2.actual &&
test_cmp rawstdin2.expected rawstdin2.actual
'
test_expect_success 'kvs: put --raw a=- b=- works with a getting all of stdin' '
flux kvs unlink -Rf $DIR &&
printf "%s" "abc" | flux kvs put --raw $DIR.a=- $DIR.b=- &&
printf "%s" "abc" >rawstdin3a.expected &&
flux kvs get --raw $DIR.a >rawstdin3a.actual &&
flux kvs get --raw $DIR.b >rawstdin3b.actual &&
test_cmp rawstdin3a.expected rawstdin3a.actual &&
test_cmp /dev/null rawstdin3b.actual
'
#
# get/put --treeobj tests
#
test_expect_success 'kvs: get --treeobj: returns dirref object for root' '
flux kvs get --treeobj . | grep -q \"dirref\"
'
test_expect_success 'kvs: treeobj of all types handled by get --treeobj' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.val=hello &&
flux kvs put $DIR.valref=$(seq -s 1 100) &&
flux kvs mkdir $DIR.dirref &&
flux kvs link foo $DIR.symlink &&
flux kvs link --target-namespace=A bar $DIR.symlinkNS &&
flux kvs get --treeobj $DIR.val | grep -q val &&
flux kvs get --treeobj $DIR.valref | grep -q valref &&
flux kvs get --treeobj $DIR.dirref | grep -q dirref &&
flux kvs get --treeobj $DIR.symlink | grep -q symlink &&
flux kvs get --treeobj $DIR.symlinkNS | grep -q symlink
'
test_expect_success 'kvs: get --treeobj: returns value ref for large value' '
flux kvs unlink -Rf $DIR &&
dd if=/dev/zero bs=4096 count=1 | flux kvs put --raw $DIR.a=- &&
flux kvs get --treeobj $DIR.a | grep -q \"valref\"
'
test_expect_success 'kvs: treeobj is created by put --treeobj' '
flux kvs unlink -Rf $DIR &&
flux kvs put --treeobj $DIR.val="{\"data\":\"YgA=\",\"type\":\"val\",\"ver\":1}" &&
flux kvs get $DIR.val >val.output &&
echo "b" >val.expected &&
test_cmp val.expected val.output
'
test_expect_success 'kvs: put --treeobj: can make root snapshot' '
flux kvs unlink -Rf $DIR &&
flux kvs get --treeobj . >snapshot &&
flux kvs put --treeobj $DIR.a="`cat snapshot`" &&
flux kvs get --treeobj $DIR.a >snapshot.cpy &&
test_cmp snapshot snapshot.cpy
'
test_expect_success 'kvs: treeobj can be used to create arbitrary snapshot' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.a.a=hello &&
flux kvs put $DIR.a.b=goodbye &&
flux kvs put --treeobj $DIR.b=$(flux kvs get --treeobj $DIR.a) &&
(flux kvs get $DIR.a.a && flux kvs get $DIR.a.b) >snap.expected &&
(flux kvs get $DIR.b.a && flux kvs get $DIR.b.b) >snap.actual &&
test_cmp snap.expected snap.actual
'
#
# get/put --treeobj corner case tests
#
test_expect_success 'kvs: put --treeobj: clobbers destination' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=42 &&
flux kvs get --treeobj . >snapshot2 &&
flux kvs put --treeobj $DIR.a="`cat snapshot2`" &&
! flux kvs get --json $DIR.a &&
flux kvs dir $DIR.a
'
test_expect_success 'kvs: put --treeobj: fails bad dirent: not JSON' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs put --treeobj $DIR.a=xyz
'
test_expect_success 'kvs: put --treeobj: fails bad dirent: unknown type' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":\"MQA=\",\"type\":\"FOO\",\"ver\":1}"
'
test_expect_success 'kvs: put --treeobj: fails bad dirent: bad link data' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":42,\"type\":\"symlink\",\"ver\":1}"
'
test_expect_success 'kvs: put --treeobj: fails bad dirent: bad ref data' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":42,\"type\":\"dirref\",\"ver\":1}" &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":"sha1-4087718d190b373fb490b27873f61552d7f29dbe",\"type\":\"dirref\",\"ver\":1}"
'
test_expect_success 'kvs: put --treeobj: fails bad dirent: bad blobref' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":[\"sha1-aaa\"],\"type\":\"dirref\",\"ver\":1}" &&
test_must_fail flux kvs put --treeobj $DIR.a="{\"data\":[\"sha1-bbb\"],\"type\":\"dirref\",\"ver\":1}"
'
#
# put --append tests
#
test_expect_success 'kvs: append on non-existent key is same as create' '
flux kvs unlink -Rf $DIR &&
flux kvs put --append $DIR.a=abc &&
printf "%s\n" "abc" >expected &&
flux kvs get $DIR.a >output &&
test_cmp output expected
'
test_expect_success 'kvs: basic append works' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.a=abc &&
flux kvs put --append $DIR.a=def &&
flux kvs put --append $DIR.a=ghi &&
printf "%s%s%s\n" "abcdefghi" >expected &&
flux kvs get $DIR.a >output &&
test_cmp output expected
'
test_expect_success 'kvs: basic append works with --raw' '
flux kvs unlink -Rf $DIR &&
flux kvs put --raw $DIR.a=abc &&
flux kvs put --append --raw $DIR.a=def &&
flux kvs put --append --raw $DIR.a=ghi &&
printf "%s" "abcdefghi" >expected &&
flux kvs get --raw $DIR.a >output &&
test_cmp output expected
'
test_expect_success 'kvs: basic append works with newlines' '
flux kvs unlink -Rf $DIR &&
echo "abc" | flux kvs put --raw $DIR.a=- &&
echo "def" | flux kvs put --append --raw $DIR.a=- &&
echo "ghi" | flux kvs put --append --raw $DIR.a=- &&
printf "%s\n%s\n%s\n" "abc" "def" "ghi" >expected &&
flux kvs get --raw $DIR.a >output &&
test_cmp output expected
'
#
# put --no-merge tests
#
test_expect_success 'kvs: put using --no-merge flag' '
flux kvs unlink -Rf $DIR &&
flux kvs put --no-merge --json $DIR.a=69 &&
flux kvs put --no-merge --json $DIR.b.c.d.e.f.g=70 &&
flux kvs put --no-merge --json $DIR.c.a.b=3.14 &&
flux kvs put --no-merge --json $DIR.d=\"snerg\" &&
flux kvs put --no-merge --json $DIR.e=true &&
flux kvs dir -R $DIR | sort >output &&
cat >expected <<EOF &&
$DIR.a = 69
$DIR.b.c.d.e.f.g = 70
$DIR.c.a.b = 3.140000
$DIR.d = snerg
$DIR.e = true
EOF
test_cmp expected output
'
#
# ls tests
#
test_expect_success 'kvs: ls -1F works' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR &&
flux kvs ls -1F >output &&
cat >expected <<-EOF &&
test.
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -1F . works' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR &&
flux kvs ls -1F . >output &&
cat >expected <<-EOF &&
test.
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -1F DIR works' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=69 &&
flux kvs mkdir $DIR.b &&
flux kvs link b $DIR.c &&
flux kvs link --target-namespace=foo c $DIR.d &&
flux kvs ls -1F $DIR >output &&
cat >expected <<-EOF &&
a
b.
c@
d@
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -1F DIR. works' '
flux kvs ls -1F $DIR. >output &&
cat >expected <<-EOF &&
a
b.
c@
d@
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -1Fd DIR.a DIR.b DIR.c DIR.d works' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=69 &&
flux kvs mkdir $DIR.b &&
flux kvs link b $DIR.c &&
flux kvs link --target-namespace=foo c $DIR.d &&
flux kvs ls -1Fd $DIR.a $DIR.b $DIR.c $DIR.d >output &&
cat >expected <<-EOF &&
$DIR.a
$DIR.b.
$DIR.c@
$DIR.d@
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -1RF shows directory titles' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=69 &&
flux kvs put --json $DIR.b.d=42 &&
flux kvs link b $DIR.c &&
flux kvs ls -1RF $DIR | grep : | wc -l >output &&
cat >expected <<-EOF &&
2
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls with no options adjusts output width to 80' '
flux kvs unlink -Rf $DIR &&
${FLUX_BUILD_DIR}/t/kvs/dtree -p$DIR -h1 -w50 &&
flux kvs ls $DIR | wc -wl >output &&
cat >expected <<-EOF &&
5 50
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -w40 adjusts output width to 40' '
flux kvs unlink -Rf $DIR &&
${FLUX_BUILD_DIR}/t/kvs/dtree -p$DIR -h1 -w50 &&
flux kvs ls -w40 $DIR | wc -wl >output &&
cat >expected <<-EOF &&
10 50
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls with COLUMNS=20 adjusts output width to 20' '
flux kvs unlink -Rf $DIR &&
${FLUX_BUILD_DIR}/t/kvs/dtree -p$DIR -h1 -w50 &&
COLUMNS=20 flux kvs ls $DIR | wc -wl >output &&
cat >expected <<-EOF &&
25 50
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls -R lists deep directory hierarchy' '
flux kvs unlink -Rf $DIR &&
${FLUX_BUILD_DIR}/t/kvs/dtree -p$DIR -h8 -w1 &&
flux kvs ls -R $DIR >output &&
cat >expected <<-EOF &&
$DIR:
0000
$DIR.0000:
0000
$DIR.0000.0000:
0000
$DIR.0000.0000.0000:
0000
$DIR.0000.0000.0000.0000:
0000
$DIR.0000.0000.0000.0000.0000:
0000
$DIR.0000.0000.0000.0000.0000.0000:
0000
$DIR.0000.0000.0000.0000.0000.0000.0000:
0000
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls key. works' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR.a &&
flux kvs ls -d $DIR.a. >output &&
cat >expected <<-EOF &&
$DIR.a
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls key. fails if key is not a directory' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a=42 &&
test_must_fail flux kvs ls -d $DIR.a.
'
test_expect_success 'kvs: ls key. fails if key does not exist' '
flux kvs unlink -Rf $DIR &&
test_must_fail flux kvs ls $DIR.a
'
test_expect_success 'kvs: ls does not follow symlink with -d' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.foo=1 &&
flux kvs link $DIR.foo $DIR.link &&
flux kvs ls -d $DIR.link >output &&
cat >expected <<-EOF &&
$DIR.link
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls does not follow symlink with -F' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.foo=1 &&
flux kvs link $DIR.foo $DIR.link &&
flux kvs ls -F $DIR.link >output &&
cat >expected <<-EOF &&
$DIR.link@
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls outputs linkname when link points to value' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.foo=1 &&
flux kvs link $DIR.foo $DIR.link &&
flux kvs ls $DIR.link >output &&
cat >expected <<-EOF &&
$DIR.link
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls outputs linkname when link points to invalid target' '
flux kvs unlink -Rf $DIR &&
flux kvs link invalid $DIR.link &&
flux kvs ls $DIR.link >output &&
cat >expected <<-EOF &&
$DIR.link
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls outputs dir when link points to dir' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.a.b=1 &&
flux kvs link $DIR.a $DIR.link &&
flux kvs ls $DIR.link >output &&
cat >expected <<-EOF &&
b
EOF
test_cmp expected output
'
test_expect_success 'kvs: ls outputs dir and header when link points to dir and -R' '
flux kvs unlink -Rf $DIR &&
flux kvs put $DIR.a.b=1 &&
flux kvs link $DIR.a $DIR.link &&
flux kvs ls -R $DIR.link >output &&
cat >expected <<-EOF &&
$DIR.link:
b
EOF
test_cmp expected output
'
test_expect_success 'kvs: namespace create setup' '
flux kvs namespace create TESTLSNS
'
test_expect_success 'kvs: ls --namespace -1F DIR works' '
flux kvs unlink --namespace=TESTLSNS -Rf $DIR.ns &&
flux kvs put --namespace=TESTLSNS --json $DIR.ns.a=69 &&
flux kvs mkdir --namespace=TESTLSNS $DIR.ns.b &&
flux kvs link --namespace=TESTLSNS b $DIR.ns.c &&
flux kvs link --namespace=TESTLSNS --target-namespace=foo c $DIR.ns.d &&
flux kvs ls --namespace=TESTLSNS -1F $DIR.ns >output &&
cat >expected <<-EOF &&
a
b.
c@
d@
EOF
test_cmp expected output
'
test_expect_success 'kvs: namespace remove cleanup' '
flux kvs namespace remove TESTLSNS
'
#
# link/readlink tests
#
test_expect_success 'kvs: link works' '
TARGET=$DIR.target &&
flux kvs put --json $TARGET=\"foo\" &&
flux kvs link $TARGET $DIR.link &&
OUTPUT=$(flux kvs get --json $DIR.link) &&
test "$OUTPUT" = "foo"
'
test_expect_success 'kvs: readlink works' '
TARGET=$DIR.target &&
flux kvs put --json $TARGET=\"foo\" &&
flux kvs link $TARGET $DIR.link &&
OUTPUT=$(flux kvs readlink $DIR.link) &&
test "$OUTPUT" = "$TARGET"
'
test_expect_success 'kvs: readlink works (multiple inputs)' '
TARGET1=$DIR.target1 &&
TARGET2=$DIR.target2 &&
flux kvs put --json $TARGET1=\"foo1\" &&
flux kvs put --json $TARGET2=\"foo2\" &&
flux kvs link $TARGET1 $DIR.link1 &&
flux kvs link $TARGET2 $DIR.link2 &&
flux kvs readlink $DIR.link1 $DIR.link2 >output &&
cat >expected <<EOF &&
$TARGET1
$TARGET2
EOF
test_cmp output expected
'
test_expect_success 'kvs: link: path resolution when intermediate component is a link' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a.b.c=42 &&
flux kvs link $DIR.a.b $DIR.Z.Y &&
OUTPUT=$(flux kvs get --json $DIR.Z.Y.c) &&
test "$OUTPUT" = "42"
'
test_expect_success 'kvs: link: intermediate link points to another link' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a.b.c=42 &&
flux kvs link $DIR.a.b $DIR.Z.Y &&
flux kvs link $DIR.Z.Y $DIR.X.W &&
test_kvs_key $DIR.X.W.c 42
'
test_expect_success 'kvs: link: intermediate links are followed by put' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR.a &&
flux kvs link $DIR.a $DIR.link &&
flux kvs readlink $DIR.link >/dev/null &&
flux kvs put --json $DIR.link.X=42 &&
flux kvs readlink $DIR.link >/dev/null &&
test_kvs_key $DIR.link.X 42 &&
test_kvs_key $DIR.a.X 42
'
# This will fail if individual ops are applied out of order
test_expect_success 'kvs: link: copy removes linked destination' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR.a &&
flux kvs link $DIR.a $DIR.link &&
flux kvs put --json $DIR.a.X=42 &&
flux kvs copy $DIR.a $DIR.link &&
! flux kvs readlink $DIR.link >/dev/null &&
test_kvs_key $DIR.link.X 42
'
# This will fail if individual ops are applied out of order
test_expect_success 'kvs: link: move works' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR.a &&
flux kvs link $DIR.a $DIR.link &&
flux kvs put --json $DIR.a.X=42 &&
flux kvs move $DIR.a $DIR.link &&
! flux kvs readlink $DIR.link >/dev/null &&
test_kvs_key $DIR.link.X 42 &&
! flux kvs dir $DIR.a >/dev/null
'
test_expect_success 'kvs: link: copy does not follow links (top)' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a.X=42 &&
flux kvs link $DIR.a $DIR.link &&
flux kvs copy $DIR.link $DIR.copy &&
LINKVAL=$(flux kvs readlink $DIR.copy) &&
test "$LINKVAL" = "$DIR.a"
'
test_expect_success 'kvs: link: copy does not follow links (mid)' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a.b.X=42 &&
flux kvs link $DIR.a.b $DIR.a.link &&
flux kvs copy $DIR.a $DIR.copy &&
LINKVAL=$(flux kvs readlink $DIR.copy.link) &&
test "$LINKVAL" = "$DIR.a.b"
'
test_expect_success 'kvs: link: copy does not follow links (bottom)' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.a.b.X=42 &&
flux kvs link $DIR.a.b.X $DIR.a.b.link &&
flux kvs copy $DIR.a $DIR.copy &&
LINKVAL=$(flux kvs readlink $DIR.copy.b.link) &&
test "$LINKVAL" = "$DIR.a.b.X"
'
test_expect_success 'kvs: link: dangling link' '
flux kvs unlink -Rf $DIR &&
flux kvs link $DIR.dangle $DIR.a.b.c
'
test_expect_success 'kvs: link: readlink on dangling link' '
flux kvs unlink -Rf $DIR &&
flux kvs link $DIR.dangle $DIR.a.b.c &&
OUTPUT=$(flux kvs readlink $DIR.a.b.c) &&
test "$OUTPUT" = "$DIR.dangle"
'
#
# link/readlink corner case tests
#
test_expect_success 'kvs: readlink fails on regular value' '
flux kvs unlink -Rf $DIR &&
flux kvs put --json $DIR.target=42 &&
! flux kvs readlink $DIR.target
'
test_expect_success 'kvs: readlink fails on directory' '
flux kvs unlink -Rf $DIR &&
flux kvs mkdir $DIR.a.b.c &&
! flux kvs readlink $DIR.a.b.
'
test_expect_success 'kvs: link: path resolution with intermediate link and nonexistent key' '
flux kvs unlink -Rf $DIR &&
flux kvs link $DIR.a.b $DIR.Z.Y &&
test_must_fail flux kvs get --json $DIR.Z.Y
'
#
# link/readlink tests - across namespace
#
test_expect_success 'kvs: namespace create setup' '
flux kvs namespace create TESTSYMLINKNS
'
test_expect_success 'kvs: symlink w/ Namespace works' '
TARGET=$DIR.target &&
flux kvs put --namespace=TESTSYMLINKNS --json $TARGET=\"foo\" &&
flux kvs link --target-namespace=TESTSYMLINKNS $TARGET $DIR.symlinkNS &&
OUTPUT=$(flux kvs get --json $DIR.symlinkNS) &&
test "$OUTPUT" = "foo"
'
test_expect_success 'kvs: symlink w/ Namespace fails on bad namespace' '
TARGET=$DIR.target &&