Fossil SCM

Minor tweaks in a few test cases, placeholder for cases to exercise documented error codes.

rberteig 2016-02-02 02:32 rberteig-json-test
Commit 9f45c8b6e0392feb9b943419ea075a278715bde7
1 file changed +177 -7
+177 -7
--- test/json.test
+++ test/json.test
@@ -516,20 +516,25 @@
516516
test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
517517
incr i
518518
}
519519
520520
# json user save
521
-fossil json user save --uid -1 --name U2 --password Utwo
521
+fossil_json user save --uid -1 --name U2 --password Utwo
522522
test_json_envelope_ok json-user-save-env
523
+test_json_payload json-user-save {uid name capabilities info timestamp} {}
524
+
525
+
523526
# DOCBUG? Doc says payload is "same as /json/user/get" but actual
524527
# result was an array of one user similar to /json/user/list.
525
-set i 0
526
-foreach u [dict get $JR payload] {
527
- test_dict_keys json-user-save-$i $u {uid name capabilities info timestamp} {}
528
- incr i
529
-}
530
-#test_json_payload json-user-save {uid name capabilities info timestamp} {}
528
+#set i 0
529
+#foreach u [dict get $JR payload] {
530
+# test_dict_keys json-user-save-$i $u {uid name capabilities info timestamp} {}
531
+# incr i
532
+#}
533
+#test json-user-save-count {$i == 1}
534
+
535
+
531536
532537
#### WIKI
533538
534539
# wiki list
535540
fossil_json wiki list
@@ -634,10 +639,13 @@
634639
set codes [dict get $JR payload]
635640
test json-resultCodes-codes-1 {[llength $codes] >= 35} ;# count as of API 20120713
636641
# foreach c $codes {
637642
# puts [dict values $c]
638643
# }
644
+foreach r $codes {
645
+ protOut "# [dict get $r resultCode] [dict get $r cSymbol]\n# [dict get $r description]"
646
+}
639647
640648
641649
642650
#### From the API Docs
643651
@@ -663,6 +671,168 @@
663671
test json-ROrepo-2-2 {[regexp {\}\s*$} $RESULT]} knownBug
664672
test json-ROrepo-2-3 {![regexp {SQLITE_[A-Z]+:} $RESULT]} knownBug
665673
#test_json_envelope_ok json-http-timeline2
666674
catch {exec chmod 666 .rep.fossil}; # Unix. What about Win?
667675
676
+
677
+#### Result Codes
678
+# Test cases designed to stimulate each (documented) error code.
679
+
680
+# FOSSIL-0000
681
+# Not returned by any command. We generally verify that in the
682
+# test_json_envelope_ok command by verifying that the resultCode
683
+# field is not present. Should any JSON endpoint begin to use the
684
+# range reserved for non-fatal warnings, those tests will fail.
685
+#
686
+# Notice that code is not included in the list returned from
687
+# /json/resultCodes.
688
+
689
+
690
+# FOSSIL-1000 FSL_JSON_E_GENERIC
691
+# Generic error
692
+
693
+# FOSSIL-1101 FSL_JSON_E_INVALID_REQUEST
694
+# Invalid request
695
+write_file e1101.json {
696
+ ["command","nope"]
697
+}
698
+fossil_json --json-input e1101.json -expectError
699
+test json-RC-1101-array-CLI-exit {$CODE != 0}
700
+test_json_envelope json-RC-1101-array-env {fossil timestamp command procTimeUs \
701
+procTimeMs resultCode resultText} {payload}
702
+test json-RC-1101-array-code {[dict get $JR resultCode] eq "FOSSIL-1101"}
703
+
704
+write_file e1101.json {
705
+ "Not really a command but more of a suggestion"
706
+}
707
+fossil_json --json-input e1101.json -expectError
708
+test json-RC-1101-string-CLI-exit {$CODE != 0}
709
+test_json_envelope json-RC-1101-string-env {fossil timestamp command procTimeUs \
710
+procTimeMs resultCode resultText} {payload}
711
+test json-RC-1101-string-code {[dict get $JR resultCode] eq "FOSSIL-1101"}
712
+
713
+
714
+
715
+
716
+# FOSSIL-1102 FSL_JSON_E_UNKNOWN_COMMAND
717
+# Unknown command or subcommand
718
+fossil_json NoSuchEndpoint -expectError
719
+test json-RC-1102-CLI-exit {$CODE != 0}
720
+test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \
721
+procTimeMs resultCode resultText} {payload}
722
+test json-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"}
723
+
724
+write_file e1102.json {
725
+ {
726
+ "command":"no/such/endpoint"
727
+ }
728
+}
729
+fossil_json --json-input e1102.json -expectError
730
+test json-env-RC-1102-CLI-exit {$CODE != 0}
731
+test_json_envelope json-env-RC-1102-env {fossil timestamp command procTimeUs \
732
+procTimeMs resultCode resultText} {payload}
733
+test json-env-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"}
734
+
735
+
736
+# FOSSIL-1103 FSL_JSON_E_UNKNOWN
737
+# Unknown error
738
+
739
+write_file bad.sql {
740
+CREATE TABLE spam(a integer, b text);
741
+}
742
+exec sqlite3 bad.fossil <bad.sql
743
+#exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql
744
+#fossil_json HAI -R bad.fossil -expectError
745
+
746
+# FOSSIL-1104 FSL_JSON_E_TIMEOUT
747
+# Timeout reached
748
+# FOSSIL-1105 FSL_JSON_E_ASSERT
749
+# Assertion failed
750
+# FOSSIL-1106 FSL_JSON_E_ALLOC
751
+# Resource allocation failed
752
+# FOSSIL-1107 FSL_JSON_E_NYI
753
+# Not yet implemented
754
+# FOSSIL-1108 FSL_JSON_E_PANIC
755
+# x
756
+# FOSSIL-1109 FSL_JSON_E_MANIFEST_READ_FAILED
757
+# Reading artifact manifest failed
758
+# FOSSIL-1110 FSL_JSON_E_FILE_OPEN_FAILED
759
+# Opening file failed
760
+
761
+# FOSSIL-2000 FSL_JSON_E_AUTH
762
+# Authentication error
763
+# FOSSIL-2001 FSL_JSON_E_MISSING_AUTH
764
+# Authentication info missing from request
765
+# FOSSIL-2002 FSL_JSON_E_DENIED
766
+# Access denied
767
+# FOSSIL-2003 FSL_JSON_E_WRONG_MODE
768
+# Request not allowed (wrong operation mode)
769
+# FOSSIL-2100 FSL_JSON_E_LOGIN_FAILED
770
+# Login failed
771
+# FOSSIL-2101 FSL_JSON_E_LOGIN_FAILED_NOSEED
772
+# Anonymous login attempt was missing password seed
773
+# FOSSIL-2102 FSL_JSON_E_LOGIN_FAILED_NONAME
774
+# Login failed - name not supplied
775
+# FOSSIL-2103 FSL_JSON_E_LOGIN_FAILED_NOPW
776
+# Login failed - password not supplied
777
+# FOSSIL-2104 FSL_JSON_E_LOGIN_FAILED_NOTFOUND
778
+# Login failed - no match found
779
+
780
+# FOSSIL-3000 FSL_JSON_E_USAGE
781
+# Usage error
782
+# FOSSIL-3001 FSL_JSON_E_INVALID_ARGS
783
+# Invalid argument(s)
784
+
785
+# FOSSIL-3002 FSL_JSON_E_MISSING_ARGS
786
+# Missing argument(s)
787
+write_file e3002.json {
788
+ {"color":"yellow",
789
+ "really":"no, blue",
790
+ "number":42
791
+ }
792
+}
793
+fossil_json --json-input e3002.json -expectError
794
+test json-RC-3002-strange-CLI-exit {$CODE != 0}
795
+test_json_envelope json-RC-3002-strange-env {fossil timestamp command procTimeUs \
796
+procTimeMs resultCode resultText} {payload}
797
+test json-RC-3002-strange-code {[dict get $JR resultCode] eq "FOSSIL-3002"}
798
+
799
+
800
+# FOSSIL-3003 FSL_JSON_E_AMBIGUOUS_UUID
801
+# Resource identifier is ambiguous
802
+# FOSSIL-3004 FSL_JSON_E_UNRESOLVED_UUID
803
+# Provided uuid/tag/branch could not be resolved
804
+# FOSSIL-3005 FSL_JSON_E_RESOURCE_ALREADY_EXISTS
805
+# Resource already exists
806
+# FOSSIL-3006 FSL_JSON_E_RESOURCE_NOT_FOUND
807
+# Resource not found
808
+
809
+# FOSSIL-4000 FSL_JSON_E_DB
810
+# Database error
811
+# FOSSIL-4001 FSL_JSON_E_STMT_PREP
812
+# Statement preparation failed
813
+# FOSSIL-4002 FSL_JSON_E_STMT_BIND
814
+# Statement parameter binding failed
815
+# FOSSIL-4003 FSL_JSON_E_STMT_EXEC
816
+# Statement execution/stepping failed
817
+# FOSSIL-4004 FSL_JSON_E_DB_LOCKED
818
+# Database is locked
819
+# FOSSIL-4101 FSL_JSON_E_DB_NEEDS_REBUILD
820
+# Fossil repository needs to be rebuilt
821
+
822
+# FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND
823
+# Fossil repository db file could not be found.
824
+fossil close
825
+fossil_json HAI -expectError
826
+test json-RC-4102-CLI-exit {$CODE != 0}
827
+test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \
828
+procTimeMs resultCode resultText} {payload}
829
+test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"}
830
+fossil open .rep.fossil
831
+
832
+# FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID
833
+# Fossil repository db file is not valid.
834
+write_file nope.fossil {
835
+This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
836
+but it is actually just a block of text.
837
+}
668838
669839
--- test/json.test
+++ test/json.test
@@ -516,20 +516,25 @@
516 test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
517 incr i
518 }
519
520 # json user save
521 fossil json user save --uid -1 --name U2 --password Utwo
522 test_json_envelope_ok json-user-save-env
 
 
 
523 # DOCBUG? Doc says payload is "same as /json/user/get" but actual
524 # result was an array of one user similar to /json/user/list.
525 set i 0
526 foreach u [dict get $JR payload] {
527 test_dict_keys json-user-save-$i $u {uid name capabilities info timestamp} {}
528 incr i
529 }
530 #test_json_payload json-user-save {uid name capabilities info timestamp} {}
 
 
531
532 #### WIKI
533
534 # wiki list
535 fossil_json wiki list
@@ -634,10 +639,13 @@
634 set codes [dict get $JR payload]
635 test json-resultCodes-codes-1 {[llength $codes] >= 35} ;# count as of API 20120713
636 # foreach c $codes {
637 # puts [dict values $c]
638 # }
 
 
 
639
640
641
642 #### From the API Docs
643
@@ -663,6 +671,168 @@
663 test json-ROrepo-2-2 {[regexp {\}\s*$} $RESULT]} knownBug
664 test json-ROrepo-2-3 {![regexp {SQLITE_[A-Z]+:} $RESULT]} knownBug
665 #test_json_envelope_ok json-http-timeline2
666 catch {exec chmod 666 .rep.fossil}; # Unix. What about Win?
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
669
--- test/json.test
+++ test/json.test
@@ -516,20 +516,25 @@
516 test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
517 incr i
518 }
519
520 # json user save
521 fossil_json user save --uid -1 --name U2 --password Utwo
522 test_json_envelope_ok json-user-save-env
523 test_json_payload json-user-save {uid name capabilities info timestamp} {}
524
525
526 # DOCBUG? Doc says payload is "same as /json/user/get" but actual
527 # result was an array of one user similar to /json/user/list.
528 #set i 0
529 #foreach u [dict get $JR payload] {
530 # test_dict_keys json-user-save-$i $u {uid name capabilities info timestamp} {}
531 # incr i
532 #}
533 #test json-user-save-count {$i == 1}
534
535
536
537 #### WIKI
538
539 # wiki list
540 fossil_json wiki list
@@ -634,10 +639,13 @@
639 set codes [dict get $JR payload]
640 test json-resultCodes-codes-1 {[llength $codes] >= 35} ;# count as of API 20120713
641 # foreach c $codes {
642 # puts [dict values $c]
643 # }
644 foreach r $codes {
645 protOut "# [dict get $r resultCode] [dict get $r cSymbol]\n# [dict get $r description]"
646 }
647
648
649
650 #### From the API Docs
651
@@ -663,6 +671,168 @@
671 test json-ROrepo-2-2 {[regexp {\}\s*$} $RESULT]} knownBug
672 test json-ROrepo-2-3 {![regexp {SQLITE_[A-Z]+:} $RESULT]} knownBug
673 #test_json_envelope_ok json-http-timeline2
674 catch {exec chmod 666 .rep.fossil}; # Unix. What about Win?
675
676
677 #### Result Codes
678 # Test cases designed to stimulate each (documented) error code.
679
680 # FOSSIL-0000
681 # Not returned by any command. We generally verify that in the
682 # test_json_envelope_ok command by verifying that the resultCode
683 # field is not present. Should any JSON endpoint begin to use the
684 # range reserved for non-fatal warnings, those tests will fail.
685 #
686 # Notice that code is not included in the list returned from
687 # /json/resultCodes.
688
689
690 # FOSSIL-1000 FSL_JSON_E_GENERIC
691 # Generic error
692
693 # FOSSIL-1101 FSL_JSON_E_INVALID_REQUEST
694 # Invalid request
695 write_file e1101.json {
696 ["command","nope"]
697 }
698 fossil_json --json-input e1101.json -expectError
699 test json-RC-1101-array-CLI-exit {$CODE != 0}
700 test_json_envelope json-RC-1101-array-env {fossil timestamp command procTimeUs \
701 procTimeMs resultCode resultText} {payload}
702 test json-RC-1101-array-code {[dict get $JR resultCode] eq "FOSSIL-1101"}
703
704 write_file e1101.json {
705 "Not really a command but more of a suggestion"
706 }
707 fossil_json --json-input e1101.json -expectError
708 test json-RC-1101-string-CLI-exit {$CODE != 0}
709 test_json_envelope json-RC-1101-string-env {fossil timestamp command procTimeUs \
710 procTimeMs resultCode resultText} {payload}
711 test json-RC-1101-string-code {[dict get $JR resultCode] eq "FOSSIL-1101"}
712
713
714
715
716 # FOSSIL-1102 FSL_JSON_E_UNKNOWN_COMMAND
717 # Unknown command or subcommand
718 fossil_json NoSuchEndpoint -expectError
719 test json-RC-1102-CLI-exit {$CODE != 0}
720 test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \
721 procTimeMs resultCode resultText} {payload}
722 test json-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"}
723
724 write_file e1102.json {
725 {
726 "command":"no/such/endpoint"
727 }
728 }
729 fossil_json --json-input e1102.json -expectError
730 test json-env-RC-1102-CLI-exit {$CODE != 0}
731 test_json_envelope json-env-RC-1102-env {fossil timestamp command procTimeUs \
732 procTimeMs resultCode resultText} {payload}
733 test json-env-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"}
734
735
736 # FOSSIL-1103 FSL_JSON_E_UNKNOWN
737 # Unknown error
738
739 write_file bad.sql {
740 CREATE TABLE spam(a integer, b text);
741 }
742 exec sqlite3 bad.fossil <bad.sql
743 #exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql
744 #fossil_json HAI -R bad.fossil -expectError
745
746 # FOSSIL-1104 FSL_JSON_E_TIMEOUT
747 # Timeout reached
748 # FOSSIL-1105 FSL_JSON_E_ASSERT
749 # Assertion failed
750 # FOSSIL-1106 FSL_JSON_E_ALLOC
751 # Resource allocation failed
752 # FOSSIL-1107 FSL_JSON_E_NYI
753 # Not yet implemented
754 # FOSSIL-1108 FSL_JSON_E_PANIC
755 # x
756 # FOSSIL-1109 FSL_JSON_E_MANIFEST_READ_FAILED
757 # Reading artifact manifest failed
758 # FOSSIL-1110 FSL_JSON_E_FILE_OPEN_FAILED
759 # Opening file failed
760
761 # FOSSIL-2000 FSL_JSON_E_AUTH
762 # Authentication error
763 # FOSSIL-2001 FSL_JSON_E_MISSING_AUTH
764 # Authentication info missing from request
765 # FOSSIL-2002 FSL_JSON_E_DENIED
766 # Access denied
767 # FOSSIL-2003 FSL_JSON_E_WRONG_MODE
768 # Request not allowed (wrong operation mode)
769 # FOSSIL-2100 FSL_JSON_E_LOGIN_FAILED
770 # Login failed
771 # FOSSIL-2101 FSL_JSON_E_LOGIN_FAILED_NOSEED
772 # Anonymous login attempt was missing password seed
773 # FOSSIL-2102 FSL_JSON_E_LOGIN_FAILED_NONAME
774 # Login failed - name not supplied
775 # FOSSIL-2103 FSL_JSON_E_LOGIN_FAILED_NOPW
776 # Login failed - password not supplied
777 # FOSSIL-2104 FSL_JSON_E_LOGIN_FAILED_NOTFOUND
778 # Login failed - no match found
779
780 # FOSSIL-3000 FSL_JSON_E_USAGE
781 # Usage error
782 # FOSSIL-3001 FSL_JSON_E_INVALID_ARGS
783 # Invalid argument(s)
784
785 # FOSSIL-3002 FSL_JSON_E_MISSING_ARGS
786 # Missing argument(s)
787 write_file e3002.json {
788 {"color":"yellow",
789 "really":"no, blue",
790 "number":42
791 }
792 }
793 fossil_json --json-input e3002.json -expectError
794 test json-RC-3002-strange-CLI-exit {$CODE != 0}
795 test_json_envelope json-RC-3002-strange-env {fossil timestamp command procTimeUs \
796 procTimeMs resultCode resultText} {payload}
797 test json-RC-3002-strange-code {[dict get $JR resultCode] eq "FOSSIL-3002"}
798
799
800 # FOSSIL-3003 FSL_JSON_E_AMBIGUOUS_UUID
801 # Resource identifier is ambiguous
802 # FOSSIL-3004 FSL_JSON_E_UNRESOLVED_UUID
803 # Provided uuid/tag/branch could not be resolved
804 # FOSSIL-3005 FSL_JSON_E_RESOURCE_ALREADY_EXISTS
805 # Resource already exists
806 # FOSSIL-3006 FSL_JSON_E_RESOURCE_NOT_FOUND
807 # Resource not found
808
809 # FOSSIL-4000 FSL_JSON_E_DB
810 # Database error
811 # FOSSIL-4001 FSL_JSON_E_STMT_PREP
812 # Statement preparation failed
813 # FOSSIL-4002 FSL_JSON_E_STMT_BIND
814 # Statement parameter binding failed
815 # FOSSIL-4003 FSL_JSON_E_STMT_EXEC
816 # Statement execution/stepping failed
817 # FOSSIL-4004 FSL_JSON_E_DB_LOCKED
818 # Database is locked
819 # FOSSIL-4101 FSL_JSON_E_DB_NEEDS_REBUILD
820 # Fossil repository needs to be rebuilt
821
822 # FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND
823 # Fossil repository db file could not be found.
824 fossil close
825 fossil_json HAI -expectError
826 test json-RC-4102-CLI-exit {$CODE != 0}
827 test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \
828 procTimeMs resultCode resultText} {payload}
829 test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"}
830 fossil open .rep.fossil
831
832 # FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID
833 # Fossil repository db file is not valid.
834 write_file nope.fossil {
835 This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
836 but it is actually just a block of text.
837 }
838
839

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button