How to use Heading method of validation Package

Best Gauge code snippet using validation.Heading

api_available_channel_test.go

Source:api_available_channel_test.go Github

copy

Full Screen

1package alerting2import (3 "fmt"4 "io/ioutil"5 "net/http"6 "testing"7 "github.com/stretchr/testify/require"8 "github.com/grafana/grafana/pkg/bus"9 "github.com/grafana/grafana/pkg/models"10 "github.com/grafana/grafana/pkg/tests/testinfra"11)12func TestAvailableChannels(t *testing.T) {13 dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{14 DisableLegacyAlerting: true,15 EnableUnifiedAlerting: true,16 DisableAnonymous: true,17 })18 grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)19 store.Bus = bus.GetBus()20 // Create a user to make authenticated requests21 createUser(t, store, models.CreateUserCommand{22 DefaultOrgRole: string(models.ROLE_EDITOR),23 Password: "password",24 Login: "grafana",25 })26 alertsURL := fmt.Sprintf("http://grafana:password@%s/api/alert-notifiers", grafanaListedAddr)27 // nolint:gosec28 resp, err := http.Get(alertsURL)29 require.NoError(t, err)30 t.Cleanup(func() {31 err := resp.Body.Close()32 require.NoError(t, err)33 })34 b, err := ioutil.ReadAll(resp.Body)35 require.NoError(t, err)36 require.Equal(t, 200, resp.StatusCode)37 require.JSONEq(t, expAvailableChannelJsonOutput, string(b))38}39var expAvailableChannelJsonOutput = `40[41 {42 "type": "dingding",43 "name": "DingDing",44 "heading": "DingDing settings",45 "description": "Sends HTTP POST request to DingDing",46 "info": "",47 "options": [48 {49 "element": "input",50 "inputType": "text",51 "label": "Url",52 "description": "",53 "placeholder": "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx",54 "propertyName": "url",55 "selectOptions": null,56 "showWhen": {57 "field": "",58 "is": ""59 },60 "required": true,61 "validationRule": "",62 "secure": false63 },64 {65 "element": "select",66 "inputType": "",67 "label": "Message Type",68 "description": "",69 "placeholder": "",70 "propertyName": "msgType",71 "selectOptions": [72 {73 "value": "link",74 "label": "Link"75 },76 {77 "value": "actionCard",78 "label": "ActionCard"79 }80 ],81 "showWhen": {82 "field": "",83 "is": ""84 },85 "required": false,86 "validationRule": "",87 "secure": false88 },89 {90 "element": "textarea",91 "inputType": "",92 "label": "Message",93 "description": "",94 "placeholder": "{{ template \"default.message\" . }}",95 "propertyName": "message",96 "selectOptions": null,97 "showWhen": {98 "field": "",99 "is": ""100 },101 "required": false,102 "validationRule": "",103 "secure": false104 }105 ]106 },107 {108 "type": "kafka",109 "name": "Kafka REST Proxy",110 "heading": "Kafka settings",111 "description": "Sends notifications to Kafka Rest Proxy",112 "info": "",113 "options": [114 {115 "element": "input",116 "inputType": "text",117 "label": "Kafka REST Proxy",118 "description": "",119 "placeholder": "http://localhost:8082",120 "propertyName": "kafkaRestProxy",121 "selectOptions": null,122 "showWhen": {123 "field": "",124 "is": ""125 },126 "required": true,127 "validationRule": "",128 "secure": false129 },130 {131 "element": "input",132 "inputType": "text",133 "label": "Topic",134 "description": "",135 "placeholder": "topic1",136 "propertyName": "kafkaTopic",137 "selectOptions": null,138 "showWhen": {139 "field": "",140 "is": ""141 },142 "required": true,143 "validationRule": "",144 "secure": false145 }146 ]147 },148 {149 "type": "email",150 "name": "Email",151 "heading": "Email settings",152 "description": "Sends notifications using Grafana server configured SMTP settings",153 "info": "",154 "options": [155 {156 "element": "checkbox",157 "inputType": "",158 "label": "Single email",159 "description": "Send a single email to all recipients",160 "placeholder": "",161 "propertyName": "singleEmail",162 "selectOptions": null,163 "showWhen": {164 "field": "",165 "is": ""166 },167 "required": false,168 "validationRule": "",169 "secure": false170 },171 {172 "element": "textarea",173 "inputType": "",174 "label": "Addresses",175 "description": "You can enter multiple email addresses using a \";\" separator",176 "placeholder": "",177 "propertyName": "addresses",178 "selectOptions": null,179 "showWhen": {180 "field": "",181 "is": ""182 },183 "required": true,184 "validationRule": "",185 "secure": false186 },187 {188 "element": "textarea",189 "inputType": "",190 "label": "Message",191 "description": "Optional message to include with the email. You can use template variables",192 "placeholder": "",193 "propertyName": "message",194 "selectOptions": null,195 "showWhen": {196 "field": "",197 "is": ""198 },199 "required": false,200 "validationRule": "",201 "secure": false202 }203 ]204 },205 {206 "type": "pagerduty",207 "name": "PagerDuty",208 "heading": "PagerDuty settings",209 "description": "Sends notifications to PagerDuty",210 "info": "",211 "options": [212 {213 "element": "input",214 "inputType": "text",215 "label": "Integration Key",216 "description": "",217 "placeholder": "Pagerduty Integration Key",218 "propertyName": "integrationKey",219 "selectOptions": null,220 "showWhen": {221 "field": "",222 "is": ""223 },224 "required": true,225 "validationRule": "",226 "secure": true227 },228 {229 "element": "select",230 "inputType": "",231 "label": "Severity",232 "description": "",233 "placeholder": "",234 "propertyName": "severity",235 "selectOptions": [236 {237 "value": "critical",238 "label": "Critical"239 },240 {241 "value": "error",242 "label": "Error"243 },244 {245 "value": "warning",246 "label": "Warning"247 },248 {249 "value": "info",250 "label": "Info"251 }252 ],253 "showWhen": {254 "field": "",255 "is": ""256 },257 "required": false,258 "validationRule": "",259 "secure": false260 },261 {262 "element": "input",263 "inputType": "text",264 "label": "Class",265 "description": "The class/type of the event, for example 'ping failure' or 'cpu load'",266 "placeholder": "",267 "propertyName": "class",268 "selectOptions": null,269 "showWhen": {270 "field": "",271 "is": ""272 },273 "required": false,274 "validationRule": "",275 "secure": false276 },277 {278 "element": "input",279 "inputType": "text",280 "label": "Component",281 "description": "Component of the source machine that is responsible for the event, for example mysql or eth0",282 "placeholder": "Grafana",283 "propertyName": "component",284 "selectOptions": null,285 "showWhen": {286 "field": "",287 "is": ""288 },289 "required": false,290 "validationRule": "",291 "secure": false292 },293 {294 "element": "input",295 "inputType": "text",296 "label": "Group",297 "description": "Logical grouping of components of a service, for example 'app-stack'",298 "placeholder": "",299 "propertyName": "group",300 "selectOptions": null,301 "showWhen": {302 "field": "",303 "is": ""304 },305 "required": false,306 "validationRule": "",307 "secure": false308 },309 {310 "element": "textarea",311 "inputType": "",312 "label": "Summary",313 "description": "You can use templates for summary",314 "placeholder": "{{ template \"default.message\" . }}",315 "propertyName": "summary",316 "selectOptions": null,317 "showWhen": {318 "field": "",319 "is": ""320 },321 "required": false,322 "validationRule": "",323 "secure": false324 }325 ]326 },327 {328 "type": "victorops",329 "name": "VictorOps",330 "heading": "VictorOps settings",331 "description": "Sends notifications to VictorOps",332 "info": "",333 "options": [334 {335 "element": "input",336 "inputType": "text",337 "label": "Url",338 "description": "",339 "placeholder": "VictorOps url",340 "propertyName": "url",341 "selectOptions": null,342 "showWhen": {343 "field": "",344 "is": ""345 },346 "required": true,347 "validationRule": "",348 "secure": false349 },350 {351 "element": "select",352 "inputType": "",353 "label": "Message Type",354 "description": "",355 "placeholder": "",356 "propertyName": "messageType",357 "selectOptions": [358 {359 "value": "CRITICAL",360 "label": "CRITICAL"361 },362 {363 "value": "WARNING",364 "label": "WARNING"365 }366 ],367 "showWhen": {368 "field": "",369 "is": ""370 },371 "required": false,372 "validationRule": "",373 "secure": false374 }375 ]376 },377 {378 "type": "pushover",379 "name": "Pushover",380 "description": "Sends HTTP POST request to the Pushover API",381 "heading": "Pushover settings",382 "info": "",383 "options": [384 {385 "element": "input",386 "inputType": "text",387 "label": "API Token",388 "description": "",389 "placeholder": "Application token",390 "propertyName": "apiToken",391 "selectOptions": null,392 "showWhen": {393 "field": "",394 "is": ""395 },396 "required": true,397 "validationRule": "",398 "secure": true399 },400 {401 "element": "input",402 "inputType": "text",403 "label": "User key(s)",404 "description": "",405 "placeholder": "comma-separated list",406 "propertyName": "userKey",407 "selectOptions": null,408 "showWhen": {409 "field": "",410 "is": ""411 },412 "required": true,413 "validationRule": "",414 "secure": true415 },416 {417 "element": "input",418 "inputType": "text",419 "label": "Device(s) (optional)",420 "description": "",421 "placeholder": "comma-separated list; leave empty to send to all devices",422 "propertyName": "device",423 "selectOptions": null,424 "showWhen": {425 "field": "",426 "is": ""427 },428 "required": false,429 "validationRule": "",430 "secure": false431 },432 {433 "element": "select",434 "inputType": "",435 "label": "Alerting priority",436 "description": "",437 "placeholder": "",438 "propertyName": "priority",439 "selectOptions": [440 {441 "value": "2",442 "label": "Emergency"443 },444 {445 "value": "1",446 "label": "High"447 },448 {449 "value": "0",450 "label": "Normal"451 },452 {453 "value": "-1",454 "label": "Low"455 },456 {457 "value": "-2",458 "label": "Lowest"459 }460 ],461 "showWhen": {462 "field": "",463 "is": ""464 },465 "required": false,466 "validationRule": "",467 "secure": false468 },469 {470 "element": "select",471 "inputType": "",472 "label": "OK priority",473 "description": "",474 "placeholder": "",475 "propertyName": "okPriority",476 "selectOptions": [477 {478 "value": "2",479 "label": "Emergency"480 },481 {482 "value": "1",483 "label": "High"484 },485 {486 "value": "0",487 "label": "Normal"488 },489 {490 "value": "-1",491 "label": "Low"492 },493 {494 "value": "-2",495 "label": "Lowest"496 }497 ],498 "showWhen": {499 "field": "",500 "is": ""501 },502 "required": false,503 "validationRule": "",504 "secure": false505 },506 {507 "element": "input",508 "inputType": "text",509 "label": "Retry (Only used for Emergency Priority)",510 "description": "How often (in seconds) the Pushover servers will send the same alerting or OK notification to the user.",511 "placeholder": "minimum 30 seconds",512 "propertyName": "retry",513 "selectOptions": null,514 "showWhen": {515 "field": "",516 "is": ""517 },518 "required": false,519 "validationRule": "",520 "secure": false521 },522 {523 "element": "input",524 "inputType": "text",525 "label": "Expire (Only used for Emergency Priority)",526 "description": "How many seconds the alerting or OK notification will continue to be retried.",527 "placeholder": "maximum 86400 seconds",528 "propertyName": "expire",529 "selectOptions": null,530 "showWhen": {531 "field": "",532 "is": ""533 },534 "required": false,535 "validationRule": "",536 "secure": false537 },538 {539 "element": "select",540 "inputType": "",541 "label": "Alerting sound",542 "description": "",543 "placeholder": "",544 "propertyName": "sound",545 "selectOptions": [546 {547 "value": "default",548 "label": "Default"549 },550 {551 "value": "pushover",552 "label": "Pushover"553 },554 {555 "value": "bike",556 "label": "Bike"557 },558 {559 "value": "bugle",560 "label": "Bugle"561 },562 {563 "value": "cashregister",564 "label": "Cashregister"565 },566 {567 "value": "classical",568 "label": "Classical"569 },570 {571 "value": "cosmic",572 "label": "Cosmic"573 },574 {575 "value": "falling",576 "label": "Falling"577 },578 {579 "value": "gamelan",580 "label": "Gamelan"581 },582 {583 "value": "incoming",584 "label": "Incoming"585 },586 {587 "value": "intermission",588 "label": "Intermission"589 },590 {591 "value": "magic",592 "label": "Magic"593 },594 {595 "value": "mechanical",596 "label": "Mechanical"597 },598 {599 "value": "pianobar",600 "label": "Pianobar"601 },602 {603 "value": "siren",604 "label": "Siren"605 },606 {607 "value": "spacealarm",608 "label": "Spacealarm"609 },610 {611 "value": "tugboat",612 "label": "Tugboat"613 },614 {615 "value": "alien",616 "label": "Alien"617 },618 {619 "value": "climb",620 "label": "Climb"621 },622 {623 "value": "persistent",624 "label": "Persistent"625 },626 {627 "value": "echo",628 "label": "Echo"629 },630 {631 "value": "updown",632 "label": "Updown"633 },634 {635 "value": "none",636 "label": "None"637 }638 ],639 "showWhen": {640 "field": "",641 "is": ""642 },643 "required": false,644 "validationRule": "",645 "secure": false646 },647 {648 "element": "select",649 "inputType": "",650 "label": "OK sound",651 "description": "",652 "placeholder": "",653 "propertyName": "okSound",654 "selectOptions": [655 {656 "value": "default",657 "label": "Default"658 },659 {660 "value": "pushover",661 "label": "Pushover"662 },663 {664 "value": "bike",665 "label": "Bike"666 },667 {668 "value": "bugle",669 "label": "Bugle"670 },671 {672 "value": "cashregister",673 "label": "Cashregister"674 },675 {676 "value": "classical",677 "label": "Classical"678 },679 {680 "value": "cosmic",681 "label": "Cosmic"682 },683 {684 "value": "falling",685 "label": "Falling"686 },687 {688 "value": "gamelan",689 "label": "Gamelan"690 },691 {692 "value": "incoming",693 "label": "Incoming"694 },695 {696 "value": "intermission",697 "label": "Intermission"698 },699 {700 "value": "magic",701 "label": "Magic"702 },703 {704 "value": "mechanical",705 "label": "Mechanical"706 },707 {708 "value": "pianobar",709 "label": "Pianobar"710 },711 {712 "value": "siren",713 "label": "Siren"714 },715 {716 "value": "spacealarm",717 "label": "Spacealarm"718 },719 {720 "value": "tugboat",721 "label": "Tugboat"722 },723 {724 "value": "alien",725 "label": "Alien"726 },727 {728 "value": "climb",729 "label": "Climb"730 },731 {732 "value": "persistent",733 "label": "Persistent"734 },735 {736 "value": "echo",737 "label": "Echo"738 },739 {740 "value": "updown",741 "label": "Updown"742 },743 {744 "value": "none",745 "label": "None"746 }747 ],748 "showWhen": {749 "field": "",750 "is": ""751 },752 "required": false,753 "validationRule": "",754 "secure": false755 },756 {757 "element": "textarea",758 "inputType": "",759 "label": "Message",760 "description": "",761 "placeholder": "{{ template \"default.message\" . }}",762 "propertyName": "message",763 "selectOptions": null,764 "showWhen": {765 "field": "",766 "is": ""767 },768 "required": false,769 "validationRule": "",770 "secure": false771 }772 ]773 },774 {775 "type": "slack",776 "name": "Slack",777 "heading": "Slack settings",778 "description": "Sends notifications to Slack",779 "info": "",780 "options": [781 {782 "element": "input",783 "inputType": "text",784 "label": "Recipient",785 "description": "Specify channel, private group, or IM channel (can be an encoded ID or a name) - required unless you provide a webhook",786 "placeholder": "",787 "propertyName": "recipient",788 "selectOptions": null,789 "showWhen": {790 "field": "",791 "is": ""792 },793 "required": false,794 "validationRule": "",795 "secure": false796 },797 {798 "element": "input",799 "inputType": "text",800 "label": "Token",801 "description": "Provide a Slack API token (starts with \"xoxb\") - required unless you provide a webhook",802 "placeholder": "",803 "propertyName": "token",804 "selectOptions": null,805 "showWhen": {806 "field": "",807 "is": ""808 },809 "required": false,810 "validationRule": "",811 "secure": true812 },813 {814 "element": "input",815 "inputType": "text",816 "label": "Username",817 "description": "Set the username for the bot's message",818 "placeholder": "",819 "propertyName": "username",820 "selectOptions": null,821 "showWhen": {822 "field": "",823 "is": ""824 },825 "required": false,826 "validationRule": "",827 "secure": false828 },829 {830 "element": "input",831 "inputType": "text",832 "label": "Icon emoji",833 "description": "Provide an emoji to use as the icon for the bot's message. Overrides the icon URL.",834 "placeholder": "",835 "propertyName": "icon_emoji",836 "selectOptions": null,837 "showWhen": {838 "field": "",839 "is": ""840 },841 "required": false,842 "validationRule": "",843 "secure": false844 },845 {846 "element": "input",847 "inputType": "text",848 "label": "Icon URL",849 "description": "Provide a URL to an image to use as the icon for the bot's message",850 "placeholder": "",851 "propertyName": "icon_url",852 "selectOptions": null,853 "showWhen": {854 "field": "",855 "is": ""856 },857 "required": false,858 "validationRule": "",859 "secure": false860 },861 {862 "element": "input",863 "inputType": "text",864 "label": "Mention Users",865 "description": "Mention one or more users (comma separated) when notifying in a channel, by ID (you can copy this from the user's Slack profile)",866 "placeholder": "",867 "propertyName": "mentionUsers",868 "selectOptions": null,869 "showWhen": {870 "field": "",871 "is": ""872 },873 "required": false,874 "validationRule": "",875 "secure": false876 },877 {878 "element": "input",879 "inputType": "text",880 "label": "Mention Groups",881 "description": "Mention one or more groups (comma separated) when notifying in a channel (you can copy this from the group's Slack profile URL)",882 "placeholder": "",883 "propertyName": "mentionGroups",884 "selectOptions": null,885 "showWhen": {886 "field": "",887 "is": ""888 },889 "required": false,890 "validationRule": "",891 "secure": false892 },893 {894 "element": "select",895 "inputType": "",896 "label": "Mention Channel",897 "description": "Mention whole channel or just active members when notifying",898 "placeholder": "",899 "propertyName": "mentionChannel",900 "selectOptions": [901 {902 "value": "",903 "label": "Disabled"904 },905 {906 "value": "here",907 "label": "Every active channel member"908 },909 {910 "value": "channel",911 "label": "Every channel member"912 }913 ],914 "showWhen": {915 "field": "",916 "is": ""917 },918 "required": false,919 "validationRule": "",920 "secure": false921 },922 {923 "element": "input",924 "inputType": "text",925 "label": "Webhook URL",926 "description": "Optionally provide a Slack incoming webhook URL for sending messages, in this case the token isn't necessary",927 "placeholder": "Slack incoming webhook URL",928 "propertyName": "url",929 "selectOptions": null,930 "showWhen": {931 "field": "",932 "is": ""933 },934 "required": false,935 "validationRule": "",936 "secure": true937 },938 {939 "element": "input",940 "inputType": "text",941 "label": "Title",942 "description": "Templated title of the slack message",943 "placeholder": "{{ template \"slack.default.title\" . }}",944 "propertyName": "title",945 "selectOptions": null,946 "showWhen": {947 "field": "",948 "is": ""949 },950 "required": false,951 "validationRule": "",952 "secure": false953 },954 {955 "element": "textarea",956 "inputType": "",957 "label": "Text Body",958 "description": "Body of the slack message",959 "placeholder": "{{ template \"slack.default.text\" . }}",960 "propertyName": "text",961 "selectOptions": null,962 "showWhen": {963 "field": "",964 "is": ""965 },966 "required": false,967 "validationRule": "",968 "secure": false969 }970 ]971 },972 {973 "type": "sensugo",974 "name": "Sensu Go",975 "description": "Sends HTTP POST request to a Sensu Go API",976 "heading": "Sensu Go Settings",977 "info": "",978 "options": [979 {980 "element": "input",981 "inputType": "text",982 "label": "Backend URL",983 "description": "",984 "placeholder": "http://sensu-api.local:8080",985 "propertyName": "url",986 "selectOptions": null,987 "showWhen": {988 "field": "",989 "is": ""990 },991 "required": true,992 "validationRule": "",993 "secure": false994 },995 {996 "element": "input",997 "inputType": "password",998 "label": "API Key",999 "description": "API key to auth to Sensu Go backend",1000 "placeholder": "",1001 "propertyName": "apikey",1002 "selectOptions": null,1003 "showWhen": {1004 "field": "",1005 "is": ""1006 },1007 "required": true,1008 "validationRule": "",1009 "secure": true1010 },1011 {1012 "element": "input",1013 "inputType": "text",1014 "label": "Proxy entity name",1015 "description": "",1016 "placeholder": "default",1017 "propertyName": "entity",1018 "selectOptions": null,1019 "showWhen": {1020 "field": "",1021 "is": ""1022 },1023 "required": false,1024 "validationRule": "",1025 "secure": false1026 },1027 {1028 "element": "input",1029 "inputType": "text",1030 "label": "Check name",1031 "description": "",1032 "placeholder": "default",1033 "propertyName": "check",1034 "selectOptions": null,1035 "showWhen": {1036 "field": "",1037 "is": ""1038 },1039 "required": false,1040 "validationRule": "",1041 "secure": false1042 },1043 {1044 "element": "input",1045 "inputType": "text",1046 "label": "Handler",1047 "description": "",1048 "placeholder": "",1049 "propertyName": "handler",1050 "selectOptions": null,1051 "showWhen": {1052 "field": "",1053 "is": ""1054 },1055 "required": false,1056 "validationRule": "",1057 "secure": false1058 },1059 {1060 "element": "input",1061 "inputType": "text",1062 "label": "Namespace",1063 "description": "",1064 "placeholder": "default",1065 "propertyName": "namespace",1066 "selectOptions": null,1067 "showWhen": {1068 "field": "",1069 "is": ""1070 },1071 "required": false,1072 "validationRule": "",1073 "secure": false1074 },1075 {1076 "element": "textarea",1077 "inputType": "",1078 "label": "Message",1079 "description": "",1080 "placeholder": "{{ template \"default.message\" . }}",1081 "propertyName": "message",1082 "selectOptions": null,1083 "showWhen": {1084 "field": "",1085 "is": ""1086 },1087 "required": false,1088 "validationRule": "",1089 "secure": false1090 }1091 ]1092 },1093 {1094 "type": "teams",1095 "name": "Microsoft Teams",1096 "heading": "Teams settings",1097 "description": "Sends notifications using Incoming Webhook connector to Microsoft Teams",1098 "info": "",1099 "options": [1100 {1101 "element": "input",1102 "inputType": "text",1103 "label": "URL",1104 "description": "",1105 "placeholder": "Teams incoming webhook url",1106 "propertyName": "url",1107 "selectOptions": null,1108 "showWhen": {1109 "field": "",1110 "is": ""1111 },1112 "required": true,1113 "validationRule": "",1114 "secure": false1115 },1116 {1117 "element": "textarea",1118 "inputType": "",1119 "label": "Message",1120 "description": "",1121 "placeholder": "{{ template \"default.message\" . }}",1122 "propertyName": "message",1123 "selectOptions": null,1124 "showWhen": {1125 "field": "",1126 "is": ""1127 },1128 "required": false,1129 "validationRule": "",1130 "secure": false1131 }1132 ]1133 },1134 {1135 "type": "telegram",1136 "name": "Telegram",1137 "heading": "Telegram API settings",1138 "description": "Sends notifications to Telegram",1139 "info": "",1140 "options": [1141 {1142 "element": "input",1143 "inputType": "text",1144 "label": "BOT API Token",1145 "description": "",1146 "placeholder": "Telegram BOT API Token",1147 "propertyName": "bottoken",1148 "selectOptions": null,1149 "showWhen": {1150 "field": "",1151 "is": ""1152 },1153 "required": true,1154 "validationRule": "",1155 "secure": true1156 },1157 {1158 "element": "input",1159 "inputType": "text",1160 "label": "Chat ID",1161 "description": "Integer Telegram Chat Identifier",1162 "placeholder": "",1163 "propertyName": "chatid",1164 "selectOptions": null,1165 "showWhen": {1166 "field": "",1167 "is": ""1168 },1169 "required": true,1170 "validationRule": "",1171 "secure": false1172 },1173 {1174 "element": "textarea",1175 "inputType": "",1176 "label": "Message",1177 "description": "",1178 "placeholder": "{{ template \"default.message\" . }}",1179 "propertyName": "message",1180 "selectOptions": null,1181 "showWhen": {1182 "field": "",1183 "is": ""1184 },1185 "required": false,1186 "validationRule": "",1187 "secure": false1188 }1189 ]1190 },1191 {1192 "type": "webhook",1193 "name": "webhook",1194 "heading": "Webhook settings",1195 "description": "Sends HTTP POST request to a URL",1196 "info": "",1197 "options": [1198 {1199 "element": "input",1200 "inputType": "text",1201 "label": "Url",1202 "description": "",1203 "placeholder": "",1204 "propertyName": "url",1205 "selectOptions": null,1206 "showWhen": {1207 "field": "",1208 "is": ""1209 },1210 "required": true,1211 "validationRule": "",1212 "secure": false1213 },1214 {1215 "element": "select",1216 "inputType": "",1217 "label": "Http Method",1218 "description": "",1219 "placeholder": "",1220 "propertyName": "httpMethod",1221 "selectOptions": [1222 {1223 "value": "POST",1224 "label": "POST"1225 },1226 {1227 "value": "PUT",1228 "label": "PUT"1229 }1230 ],1231 "showWhen": {1232 "field": "",1233 "is": ""1234 },1235 "required": false,1236 "validationRule": "",1237 "secure": false1238 },1239 {1240 "element": "input",1241 "inputType": "text",1242 "label": "Username",1243 "description": "",1244 "placeholder": "",1245 "propertyName": "username",1246 "selectOptions": null,1247 "showWhen": {1248 "field": "",1249 "is": ""1250 },1251 "required": false,1252 "validationRule": "",1253 "secure": false1254 },1255 {1256 "element": "input",1257 "inputType": "password",1258 "label": "Password",1259 "description": "",1260 "placeholder": "",1261 "propertyName": "password",1262 "selectOptions": null,1263 "showWhen": {1264 "field": "",1265 "is": ""1266 },1267 "required": false,1268 "validationRule": "",1269 "secure": true1270 },1271 {1272 "element": "input",1273 "inputType": "text",1274 "label": "Max Alerts",1275 "description": "Max alerts to include in a notification. Remaining alerts in the same batch will be ignored above this number. 0 means no limit.",1276 "placeholder": "",1277 "propertyName": "maxAlerts",1278 "selectOptions": null,1279 "showWhen": {1280 "field": "",1281 "is": ""1282 },1283 "required": false,1284 "validationRule": "",1285 "secure": false1286 }1287 ]1288 },1289 {1290 "type": "wecom",1291 "name": "WeCom",1292 "heading": "WeCom settings",1293 "description": "Send alerts generated by Grafana to WeCom",1294 "info": "",1295 "options": [1296 {1297 "element": "input",1298 "inputType": "text",1299 "label": "Url",1300 "description": "",1301 "placeholder": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx",1302 "propertyName": "url",1303 "selectOptions": null,1304 "showWhen": {1305 "field": "",1306 "is": ""1307 },1308 "required": true,1309 "validationRule": "",1310 "secure": true1311 },1312 {1313 "element": "textarea",1314 "inputType": "",1315 "label": "Message",1316 "description": "Custom WeCom message. You can use template variables.",1317 "placeholder": "{{ template \"default.message\" . }}",1318 "propertyName": "message",1319 "selectOptions": null,1320 "showWhen": {1321 "field": "",1322 "is": ""1323 },1324 "required": false,1325 "validationRule": "",1326 "secure": false1327 }1328 ]1329 },1330 {1331 "type": "prometheus-alertmanager",1332 "name": "Alertmanager",1333 "heading": "Alertmanager Settings",1334 "description": "Sends notifications to Alertmanager",1335 "info": "",1336 "options": [1337 {1338 "element": "input",1339 "inputType": "text",1340 "label": "URL",1341 "description": "",1342 "placeholder": "http://localhost:9093",1343 "propertyName": "url",1344 "selectOptions": null,1345 "showWhen": {1346 "field": "",1347 "is": ""1348 },1349 "required": true,1350 "validationRule": "",1351 "secure": false1352 },1353 {1354 "element": "input",1355 "inputType": "text",1356 "label": "Basic Auth User",1357 "description": "",1358 "placeholder": "",1359 "propertyName": "basicAuthUser",1360 "selectOptions": null,1361 "showWhen": {1362 "field": "",1363 "is": ""1364 },1365 "required": false,1366 "validationRule": "",1367 "secure": false1368 },1369 {1370 "element": "input",1371 "inputType": "password",1372 "label": "Basic Auth Password",1373 "description": "",1374 "placeholder": "",1375 "propertyName": "basicAuthPassword",1376 "selectOptions": null,1377 "showWhen": {1378 "field": "",1379 "is": ""1380 },1381 "required": false,1382 "validationRule": "",1383 "secure": true1384 }1385 ]1386 },1387 {1388 "type": "discord",1389 "name": "Discord",1390 "heading": "Discord settings",1391 "description": "Sends notifications to Discord",1392 "info": "",1393 "options": [1394 {1395 "label": "Message Content",1396 "description": "Mention a group using @ or a user using <@ID> when notifying in a channel",1397 "element": "input",1398 "inputType": "text",1399 "placeholder": "{{ template \"default.message\" . }}",1400 "propertyName": "message",1401 "selectOptions": null,1402 "showWhen": {1403 "field": "",1404 "is": ""1405 },1406 "required": false,1407 "validationRule": "",1408 "secure": false1409 },1410 {1411 "label": "Webhook URL",1412 "description": "",1413 "element": "input",1414 "inputType": "text",1415 "placeholder": "Discord webhook URL",1416 "propertyName": "url",1417 "selectOptions": null,1418 "showWhen": {1419 "field": "",1420 "is": ""1421 },1422 "required": true,1423 "validationRule": "",1424 "secure": false1425 },1426 {1427 "label": "Avatar URL",1428 "description": "",1429 "element": "input",1430 "inputType": "text",1431 "placeholder": "",1432 "propertyName": "avatar_url",1433 "selectOptions": null,1434 "showWhen": {1435 "field": "",1436 "is": ""1437 },1438 "required": false,1439 "validationRule": "",1440 "secure": false1441 },1442 {1443 "element": "checkbox",1444 "inputType": "",1445 "label": "Use Discord's Webhook Username",1446 "description": "Use the username configured in Discord's webhook settings. Otherwise, the username will be 'Grafana'",1447 "placeholder": "",1448 "propertyName": "use_discord_username",1449 "selectOptions": null,1450 "showWhen": {1451 "field": "",1452 "is": ""1453 },1454 "required": false,1455 "validationRule": "",1456 "secure": false1457 }1458 ]1459 },1460 {1461 "type": "googlechat",1462 "name": "Google Hangouts Chat",1463 "heading": "Google Hangouts Chat settings",1464 "description": "Sends notifications to Google Hangouts Chat via webhooks based on the official JSON message format",1465 "info": "",1466 "options": [1467 {1468 "element": "input",1469 "inputType": "text",1470 "label": "Url",1471 "description": "",1472 "placeholder": "Google Hangouts Chat incoming webhook url",1473 "propertyName": "url",1474 "selectOptions": null,1475 "showWhen": {1476 "field": "",1477 "is": ""1478 },1479 "required": true,1480 "validationRule": "",1481 "secure": false1482 },1483 {1484 "element": "textarea",1485 "inputType": "",1486 "label": "Message",1487 "description": "",1488 "placeholder": "{{ template \"default.message\" . }}",1489 "propertyName": "message",1490 "selectOptions": null,1491 "showWhen": {1492 "field": "",1493 "is": ""1494 },1495 "required": false,1496 "validationRule": "",1497 "secure": false1498 }1499 ]1500 },1501 {1502 "type": "LINE",1503 "name": "LINE",1504 "heading": "LINE notify settings",1505 "description": "Send notifications to LINE notify",1506 "info": "",1507 "options": [1508 {1509 "element": "input",1510 "inputType": "text",1511 "label": "Token",1512 "description": "",1513 "placeholder": "LINE notify token key",1514 "propertyName": "token",1515 "selectOptions": null,1516 "showWhen": {1517 "field": "",1518 "is": ""1519 },1520 "required": true,1521 "validationRule": "",1522 "secure": true1523 }1524 ]1525 },1526 {1527 "type": "threema",1528 "name": "Threema Gateway",1529 "heading": "Threema Gateway settings",1530 "description": "Sends notifications to Threema using Threema Gateway (Basic IDs)",1531 "info": "Notifications can be configured for any Threema Gateway ID of type \"Basic\". End-to-End IDs are not currently supported.The Threema Gateway ID can be set up at https://gateway.threema.ch/.",1532 "options": [1533 {1534 "element": "input",1535 "inputType": "text",1536 "label": "Gateway ID",1537 "description": "Your 8 character Threema Gateway Basic ID (starting with a *).",1538 "placeholder": "*3MAGWID",1539 "propertyName": "gateway_id",1540 "selectOptions": null,1541 "showWhen": {1542 "field": "",1543 "is": ""1544 },1545 "required": true,1546 "validationRule": "\\*[0-9A-Z]{7}",1547 "secure": false1548 },1549 {1550 "element": "input",1551 "inputType": "text",1552 "label": "Recipient ID",1553 "description": "The 8 character Threema ID that should receive the alerts.",1554 "placeholder": "YOUR3MID",1555 "propertyName": "recipient_id",1556 "selectOptions": null,1557 "showWhen": {1558 "field": "",1559 "is": ""1560 },1561 "required": true,1562 "validationRule": "[0-9A-Z]{8}",1563 "secure": false1564 },1565 {1566 "element": "input",1567 "inputType": "text",1568 "label": "API Secret",1569 "description": "Your Threema Gateway API secret.",1570 "placeholder": "",1571 "propertyName": "api_secret",1572 "selectOptions": null,1573 "showWhen": {1574 "field": "",1575 "is": ""1576 },1577 "required": true,1578 "validationRule": "",1579 "secure": true1580 }1581 ]1582 },1583 {1584 "type": "opsgenie",1585 "name": "OpsGenie",1586 "heading": "OpsGenie settings",1587 "description": "Sends notifications to OpsGenie",1588 "info": "",1589 "options": [1590 {1591 "element": "input",1592 "inputType": "text",1593 "label": "API Key",1594 "description": "",1595 "placeholder": "OpsGenie API Key",1596 "propertyName": "apiKey",1597 "selectOptions": null,1598 "showWhen": {1599 "field": "",1600 "is": ""1601 },1602 "required": true,1603 "validationRule": "",1604 "secure": true1605 },1606 {1607 "element": "input",1608 "inputType": "text",1609 "label": "Alert API Url",1610 "description": "",1611 "placeholder": "https://api.opsgenie.com/v2/alerts",1612 "propertyName": "apiUrl",1613 "selectOptions": null,1614 "showWhen": {1615 "field": "",1616 "is": ""1617 },1618 "required": true,1619 "validationRule": "",1620 "secure": false1621 },1622 {1623 "element": "checkbox",1624 "inputType": "",1625 "label": "Auto close incidents",1626 "description": "Automatically close alerts in OpsGenie once the alert goes back to ok.",1627 "placeholder": "",1628 "propertyName": "autoClose",1629 "selectOptions": null,1630 "showWhen": {1631 "field": "",1632 "is": ""1633 },1634 "required": false,1635 "validationRule": "",1636 "secure": false1637 },1638 {1639 "element": "checkbox",1640 "inputType": "",1641 "label": "Override priority",1642 "description": "Allow the alert priority to be set using the og_priority annotation",1643 "placeholder": "",1644 "propertyName": "overridePriority",1645 "selectOptions": null,1646 "showWhen": {1647 "field": "",1648 "is": ""1649 },1650 "required": false,1651 "validationRule": "",1652 "secure": false1653 },1654 {1655 "element": "select",1656 "inputType": "",1657 "label": "Send notification tags as",1658 "description": "Send the common annotations to Opsgenie as either Extra Properties, Tags or both",1659 "placeholder": "",1660 "propertyName": "sendTagsAs",1661 "selectOptions": [1662 {1663 "value": "tags",1664 "label": "Tags"1665 },1666 {1667 "value": "details",1668 "label": "Extra Properties"1669 },1670 {1671 "value": "both",1672 "label": "Tags & Extra Properties"1673 }1674 ],1675 "showWhen": {1676 "field": "",1677 "is": ""1678 },1679 "required": false,1680 "validationRule": "",1681 "secure": false1682 }1683 ]1684 }1685]1686`...

Full Screen

Full Screen

storage_test.go

Source:storage_test.go Github

copy

Full Screen

1package storage2import (3 "testing"4 "github.com/stretchr/testify/assert"5)6func Test_ValidateMetadata(t *testing.T) {7 tests := []struct {8 name string9 metadata Metadata10 err bool11 errMessage string12 }{13 {14 name: "Validation fails when metadata has no title",15 metadata: Metadata{16 Version: "1.0.0",17 Maintainers: []Maintainer{18 {19 Name: "Bill Bob",20 Email: "bill@gmail.com",21 },22 {23 Name: "Medhir Bhargava",24 Email: "email@gmail.com",25 },26 },27 Company: "BigCorp",28 Website: "https://www.wikipedia.com",29 Source: "https://github.com",30 License: "All rights reserved",31 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",32 },33 err: true,34 errMessage: "metadata must have a title",35 },36 {37 name: "Validation fails when metadata has no version",38 metadata: Metadata{39 Title: "App title 1",40 Maintainers: []Maintainer{41 {42 Name: "Bill Bob",43 Email: "bill@gmail.com",44 },45 {46 Name: "Medhir Bhargava",47 Email: "email@gmail.com",48 },49 },50 Company: "BigCorp",51 Website: "https://www.wikipedia.com",52 Source: "https://github.com",53 License: "All rights reserved",54 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",55 },56 err: true,57 errMessage: "metadata must have a version",58 },59 {60 name: "Validation fails when metadata has an improperly formatted version",61 metadata: Metadata{62 Title: "App title 1",63 Version: "version 2.2",64 Maintainers: []Maintainer{65 {66 Name: "Bill Bob",67 Email: "bill@gmail.com",68 },69 {70 Name: "Medhir Bhargava",71 Email: "email@gmail.com",72 },73 },74 Company: "BigCorp",75 Website: "https://www.wikipedia.com",76 Source: "https://github.com",77 License: "All rights reserved",78 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",79 },80 err: true,81 errMessage: "version must follow the semantic versioning scheme: https://semver.org",82 },83 {84 name: "Validation fails when metadata has no maintainer list",85 metadata: Metadata{86 Title: "App title 1",87 Version: "1.0.0",88 Company: "BigCorp",89 Website: "https://www.wikipedia.com",90 Source: "https://github.com",91 License: "All rights reserved",92 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",93 },94 err: true,95 errMessage: "metadata must have a list of maintainers, each of which has a name and email attribute",96 },97 {98 name: "Validation fails when maintainer is missing a name",99 metadata: Metadata{100 Title: "App title 1",101 Version: "1.0.0",102 Maintainers: []Maintainer{103 {104 Email: "bill@gmail.com",105 },106 {107 Name: "Medhir Bhargava",108 Email: "email@gmail.com",109 },110 },111 Company: "BigCorp",112 Website: "https://www.wikipedia.com",113 Source: "https://github.com",114 License: "All rights reserved",115 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",116 },117 err: true,118 errMessage: "maintainer must have a name",119 },120 {121 name: "Validation fails when maintainer is missing an email",122 metadata: Metadata{123 Title: "App title 1",124 Version: "1.0.0",125 Maintainers: []Maintainer{126 {127 Name: "Bill Bob",128 Email: "bill@gmail.com",129 },130 {131 Name: "Medhir Bhargava",132 },133 },134 Company: "BigCorp",135 Website: "https://www.wikipedia.com",136 Source: "https://github.com",137 License: "All rights reserved",138 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",139 },140 err: true,141 errMessage: "maintainer must have an email",142 },143 {144 name: "Validation fails when maintainer has an improperly formatted email",145 metadata: Metadata{146 Title: "App title 1",147 Version: "1.0.0",148 Maintainers: []Maintainer{149 {150 Name: "Bill Bob",151 Email: "bill@gmail.com",152 },153 {154 Name: "Medhir Bhargava",155 Email: "mailmedhir.com",156 },157 },158 Company: "BigCorp",159 Website: "https://www.wikipedia.com",160 Source: "https://github.com",161 License: "All rights reserved",162 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",163 },164 err: true,165 errMessage: "email must be a properly formatted email address",166 },167 {168 name: "Validation fails when maintainer has an email that does not exist",169 metadata: Metadata{170 Title: "App title 1",171 Version: "1.0.0",172 Maintainers: []Maintainer{173 {174 Name: "Bill Bob",175 Email: "bill@gmail.com",176 },177 {178 Name: "Medhir Bhargava",179 Email: "snailmail@flipflapjack.com",180 },181 },182 Company: "BigCorp",183 Website: "https://www.wikipedia.com",184 Source: "https://github.com",185 License: "All rights reserved",186 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",187 },188 err: true,189 errMessage: "email must be a valid email address",190 },191 {192 name: "Validation fails when metadata has no company",193 metadata: Metadata{194 Title: "App title 1",195 Version: "1.0.0",196 Maintainers: []Maintainer{197 {198 Name: "Bill Bob",199 Email: "bill@gmail.com",200 },201 {202 Name: "Medhir Bhargava",203 Email: "email@gmail.com",204 },205 },206 Website: "https://www.wikipedia.com",207 Source: "https://github.com",208 License: "All rights reserved",209 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",210 },211 err: true,212 errMessage: "metadata must have a company",213 },214 {215 name: "Validation fails when metadata has no website",216 metadata: Metadata{217 Title: "App title 1",218 Version: "1.0.0",219 Maintainers: []Maintainer{220 {221 Name: "Bill Bob",222 Email: "bill@gmail.com",223 },224 {225 Name: "Medhir Bhargava",226 Email: "email@gmail.com",227 },228 },229 Company: "BigCorp",230 Source: "https://github.com",231 License: "All rights reserved",232 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",233 },234 err: true,235 errMessage: "metadata must have a website",236 },237 {238 name: "Validation fails when website is an invalid URL",239 metadata: Metadata{240 Title: "App title 1",241 Version: "1.0.0",242 Maintainers: []Maintainer{243 {244 Name: "Bill Bob",245 Email: "bill@gmail.com",246 },247 {248 Name: "Medhir Bhargava",249 Email: "email@gmail.com",250 },251 },252 Company: "BigCorp",253 Website: "https//wwwwikipedia.com",254 Source: "https://github.com",255 License: "All rights reserved",256 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",257 },258 err: true,259 errMessage: "metadata must have a website with a valid URL",260 },261 {262 name: "Validation fails when metadata has no source",263 metadata: Metadata{264 Title: "App title 1",265 Version: "1.0.0",266 Maintainers: []Maintainer{267 {268 Name: "Bill Bob",269 Email: "bill@gmail.com",270 },271 {272 Name: "Medhir Bhargava",273 Email: "email@gmail.com",274 },275 },276 Company: "BigCorp",277 Website: "https://www.wikipedia.com",278 License: "All rights reserved",279 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",280 },281 err: true,282 errMessage: "metadata must have a source",283 },284 {285 name: "Validation fails when source has an invalid URL",286 metadata: Metadata{287 Title: "App title 1",288 Version: "1.0.0",289 Maintainers: []Maintainer{290 {291 Name: "Bill Bob",292 Email: "bill@gmail.com",293 },294 {295 Name: "Medhir Bhargava",296 Email: "email@gmail.com",297 },298 },299 Company: "BigCorp",300 Website: "https://www.wikipedia.com",301 Source: "httpsgithub.com",302 License: "All rights reserved",303 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",304 },305 err: true,306 errMessage: "metadata must have a source with a valid URL",307 },308 {309 name: "Validation fails when metadata has no license",310 metadata: Metadata{311 Title: "App title 1",312 Version: "1.0.0",313 Maintainers: []Maintainer{314 {315 Name: "Bill Bob",316 Email: "bill@gmail.com",317 },318 {319 Name: "Medhir Bhargava",320 Email: "email@gmail.com",321 },322 },323 Company: "BigCorp",324 Website: "https://www.wikipedia.com",325 Source: "https://github.com",326 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",327 },328 err: true,329 errMessage: "metadata must have a license",330 },331 {332 name: "Validation fails when metadata has no description",333 metadata: Metadata{334 Title: "App title 1",335 Version: "1.0.0",336 Maintainers: []Maintainer{337 {338 Name: "Bill Bob",339 Email: "bill@gmail.com",340 },341 {342 Name: "Medhir Bhargava",343 Email: "email@gmail.com",344 },345 },346 Company: "BigCorp",347 Website: "https://www.wikipedia.com",348 Source: "https://github.com",349 License: "All rights reserved",350 },351 err: true,352 errMessage: "metadata must have a description",353 },354 {355 name: "Validation succeeds when all metadata fields are present and properly formatted",356 metadata: Metadata{357 Title: "App title 1",358 Version: "1.0.0",359 Maintainers: []Maintainer{360 {361 Name: "Bill Bob",362 Email: "bill@gmail.com",363 },364 {365 Name: "Medhir Bhargava",366 Email: "email@gmail.com",367 },368 },369 Company: "BigCorp",370 Website: "https://www.wikipedia.com",371 Source: "https://github.com",372 License: "All rights reserved",373 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",374 },375 err: false,376 },377 }378 s := &Storage{}379 for _, tt := range tests {380 t.Run(tt.name, func(t *testing.T) {381 err := s.ValidateMetadata(&tt.metadata)382 if tt.err {383 assert.Error(t, err)384 if err != nil {385 assert.Equal(t, tt.errMessage, err.Error())386 }387 } else {388 assert.NoError(t, err)389 }390 })391 }392}393func Test_AddDocument(t *testing.T) {394 s := NewStorage()395 md := &Metadata{396 Title: "App title 1",397 Version: "1.0.0",398 Maintainers: []Maintainer{399 {400 Name: "Bill Bob",401 Email: "bill@gmail.com",402 },403 {404 Name: "Medhir Bhargava",405 Email: "email@gmail.com",406 },407 },408 Company: "BigCorp",409 Website: "https://www.wikipedia.com",410 Source: "https://github.com",411 License: "All rights reserved",412 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)",413 }414 err := s.AddMetadata(md)415 assert.NoError(t, err)416 // check title417 checkIndexForTokens(t, md.Title, md, s.index.title)418 // check version419 assert.NotEmpty(t, s.index.version[md.Version])420 assert.Equal(t, md, s.index.version[md.Version][0])421 // check maintainers422 for _, maintainer := range md.Maintainers {423 checkIndexForTokens(t, maintainer.Name, md, s.index.maintainerName)424 checkIndexForTokens(t, maintainer.Email, md, s.index.maintainerEmail)425 }426 // check company427 checkIndexForTokens(t, md.Company, md, s.index.company)428 // check website429 checkIndexForTokens(t, md.Website, md, s.index.website)430 // check source431 checkIndexForTokens(t, md.Source, md, s.index.source)432 // check license433 checkIndexForTokens(t, md.License, md, s.index.license)434 // check description435 checkIndexForTokens(t, md.Description, md, s.index.description)436}437func checkIndexForTokens(t *testing.T, text string, md *Metadata, field map[string][]*Metadata) {438 tokens, err := processText(text)439 assert.NoError(t, err)440 for _, token := range tokens {441 assert.NotEmpty(t, field[token])442 assert.Equal(t, md, field[token][0])443 }444}445func Test_retrieveDocuments(t *testing.T) {446 s := NewStorage()447 documents := []*Metadata{448 {449 Title: "App title 1",450 Version: "1.0.0",451 Maintainers: []Maintainer{452 {453 Name: "Bill Bob",454 Email: "bill@gmail.com",455 },456 {457 Name: "Medhir Bhargava",458 Email: "email@gmail.com",459 },460 },461 Company: "BigCorp",462 Website: "https://www.wikipedia.com",463 Source: "https://github.com/app1",464 License: "MIT",465 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)\nThe quick blue fox jumped on the hen.",466 },467 {468 Title: "App title 2",469 Version: "2.0.1",470 Maintainers: []Maintainer{471 {472 Name: "Billy Bob",473 Email: "billy@gmail.com",474 },475 {476 Name: "Medhir Bhargava",477 Email: "email@gmail.com",478 },479 },480 Company: "SmallCorp",481 Website: "https://www.smallcorp.com",482 Source: "https://github.com/app2",483 License: "Apache-2.0",484 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)\nThe quick brown fox jumped on the hen.",485 },486 }487 for _, document := range documents {488 err := s.AddMetadata(document)489 assert.NoError(t, err)490 }491 // exercise search against titles492 results, err := s.retrieveDocuments("title", "app title 1")493 assert.NoError(t, err)494 assert.Equal(t, 1, len(results))495 assert.Equal(t, documents[0], results[0])496 results, err = s.retrieveDocuments("title", "app title 2")497 assert.NoError(t, err)498 assert.Equal(t, 1, len(results))499 assert.Equal(t, documents[1], results[0])500 results, err = s.retrieveDocuments("title", "app title")501 assert.NoError(t, err)502 assert.Equal(t, 2, len(results))503 assert.Contains(t, results, documents[0])504 assert.Contains(t, results, documents[1])505 results, err = s.retrieveDocuments("title", "application name")506 assert.NoError(t, err)507 assert.Empty(t, results)508 // exercise search against versions509 results, err = s.retrieveDocuments("version", "1.0.0")510 assert.NoError(t, err)511 assert.Equal(t, 1, len(results))512 assert.Equal(t, documents[0], results[0])513 results, err = s.retrieveDocuments("version", "1.0.2")514 assert.NoError(t, err)515 assert.Empty(t, results)516 // exercise search against maintainer name517 results, err = s.retrieveDocuments("maintainer_name", "Billy")518 assert.NoError(t, err)519 assert.Equal(t, 1, len(results))520 assert.Equal(t, documents[1], results[0])521 results, err = s.retrieveDocuments("maintainer_name", "Joanne")522 assert.NoError(t, err)523 assert.Empty(t, results)524 // exercise search against maintainer email525 results, err = s.retrieveDocuments("maintainer_email", "email@gmail.com")526 assert.NoError(t, err)527 assert.Equal(t, 2, len(results))528 assert.Contains(t, results, documents[0])529 assert.Contains(t, results, documents[1])530 results, err = s.retrieveDocuments("maintainer_email", "snail@gmail.com")531 assert.NoError(t, err)532 assert.Empty(t, results)533 // exercise search against company534 results, err = s.retrieveDocuments("company", "SmallCorp")535 assert.NoError(t, err)536 assert.Equal(t, 1, len(results))537 assert.Equal(t, documents[1], results[0])538 results, err = s.retrieveDocuments("company", "MediumCorp")539 assert.NoError(t, err)540 assert.Empty(t, results)541 // exercise search against website542 results, err = s.retrieveDocuments("website", "smallcorp.com")543 assert.NoError(t, err)544 assert.Equal(t, 1, len(results))545 assert.Equal(t, documents[1], results[0])546 results, err = s.retrieveDocuments("website", "medhir.com")547 assert.NoError(t, err)548 assert.Empty(t, results)549 // search against source550 results, err = s.retrieveDocuments("source", "github.com")551 assert.NoError(t, err)552 assert.Equal(t, 2, len(results))553 assert.Contains(t, results, documents[0])554 assert.Contains(t, results, documents[1])555 results, err = s.retrieveDocuments("source", "gitlab.com")556 assert.NoError(t, err)557 assert.Empty(t, results)558 // exercise search against license559 results, err = s.retrieveDocuments("license", "MIT")560 assert.NoError(t, err)561 assert.Equal(t, 1, len(results))562 assert.Equal(t, documents[0], results[0])563 results, err = s.retrieveDocuments("license", "apache")564 assert.NoError(t, err)565 assert.Equal(t, 1, len(results))566 assert.Equal(t, documents[1], results[0])567 results, err = s.retrieveDocuments("license", "GPL")568 assert.NoError(t, err)569 assert.Empty(t, results)570 // exercise search against description571 results, err = s.retrieveDocuments("description", "quick blue fox")572 assert.NoError(t, err)573 assert.Equal(t, 1, len(results))574 assert.Equal(t, documents[0], results[0])575 results, err = s.retrieveDocuments("description", "quick brown fox")576 assert.NoError(t, err)577 assert.Equal(t, 1, len(results))578 assert.Equal(t, documents[1], results[0])579 results, err = s.retrieveDocuments("description", "quick fox")580 assert.NoError(t, err)581 assert.Equal(t, 2, len(results))582 assert.Contains(t, results, documents[0])583 assert.Contains(t, results, documents[1])584 results, err = s.retrieveDocuments("description", "dog jumped over the moon")585 assert.NoError(t, err)586 assert.Empty(t, results)587}588func Test_LookupMetadata(t *testing.T) {589 s := NewStorage()590 documents := []*Metadata{591 {592 Title: "App title 1",593 Version: "1.0.0",594 Maintainers: []Maintainer{595 {596 Name: "Bill Bob",597 Email: "bill@gmail.com",598 },599 {600 Name: "Medhir Bhargava",601 Email: "email@gmail.com",602 },603 },604 Company: "BigCorp",605 Website: "https://www.wikipedia.com",606 Source: "https://github.com/app1",607 License: "MIT",608 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)\nThe quick blue fox jumped on the hen.",609 },610 {611 Title: "App title 2",612 Version: "2.0.1",613 Maintainers: []Maintainer{614 {615 Name: "Billy Bob",616 Email: "billy@gmail.com",617 },618 {619 Name: "Medhir Bhargava",620 Email: "email@gmail.com",621 },622 },623 Company: "SmallCorp",624 Website: "https://www.smallcorp.com",625 Source: "https://github.com/app2",626 License: "Apache-2.0",627 Description: "# A main heading\n## A secondary heading\nA paragraph\n![an image](https://image.com/png)\nThe quick brown fox jumped on the hen.",628 },629 }630 for _, document := range documents {631 err := s.AddMetadata(document)632 assert.NoError(t, err)633 }634 results, err := s.LookupMetadata(map[string]string{635 "title": "app title",636 "company": "smallcorp",637 })638 assert.NoError(t, err)639 assert.Equal(t, 1, len(results))640 assert.Equal(t, documents[1], results[0])641 results, err = s.LookupMetadata(map[string]string{642 "license": "apache",643 })644 assert.NoError(t, err)645 assert.Equal(t, 1, len(results))646 assert.Equal(t, documents[1], results[0])647 results, err = s.LookupMetadata(map[string]string{648 "title": "app title",649 "license": "apache",650 "description": "no match",651 })652 assert.NoError(t, err)653 assert.Empty(t, results)654}...

Full Screen

Full Screen

xmlReportBuilder_test.go

Source:xmlReportBuilder_test.go Github

copy

Full Screen

...14 TestingT(t)15}16type MySuite struct{}17var _ = Suite(&MySuite{})18func (s *MySuite) TestGetSpecNameWhenHeadingIsPresent(c *C) {19 want := "heading"20 got := getSpecName(&gauge_messages.ProtoSpec{SpecHeading: "heading"})21 c.Assert(want, Equals, got)22}23func (s *MySuite) TestGetSpecNameWhenHeadingIsNotPresent(c *C) {24 want := "example.spec"25 got := getSpecName(&gauge_messages.ProtoSpec{FileName: filepath.Join("specs", "specs1", "example.spec")})26 c.Assert(want, Equals, got)27}28func (s *MySuite) TestHasParseErrors(c *C) {29 errors := []*gauge_messages.Error{30 {Type: gauge_messages.Error_PARSE_ERROR},31 {Type: gauge_messages.Error_VALIDATION_ERROR},32 }33 got := hasParseErrors(errors)34 c.Assert(true, Equals, got)35}36func (s *MySuite) TestHasParseErrorsWithNoErrors(c *C) {37 errors := []*gauge_messages.Error{}38 got := hasParseErrors(errors)39 c.Assert(false, Equals, got)40}41func (s *MySuite) TestHasParseErrorsWithOnyValidationErrors(c *C) {42 errors := []*gauge_messages.Error{43 {Type: gauge_messages.Error_VALIDATION_ERROR},44 {Type: gauge_messages.Error_VALIDATION_ERROR},45 }46 got := hasParseErrors(errors)47 c.Assert(false, Equals, got)48}49func (s *MySuite) TestGetErrorTestCase(c *C) {50 res := &gauge_messages.ProtoSpecResult{51 ProtoSpec: &gauge_messages.ProtoSpec{52 SpecHeading: "heading",53 },54 Errors: []*gauge_messages.Error{55 {56 Type: gauge_messages.Error_PARSE_ERROR,57 Message: "parse error",58 },59 {60 Type: gauge_messages.Error_VALIDATION_ERROR,61 Message: "validation error",62 },63 },64 ExecutionTime: int64(1),65 }66 want := JUnitTestCase{...

Full Screen

Full Screen

Heading

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the string")4 fmt.Scanln(&str)5 result = validation.Heading(str)6 if result == true {7 fmt.Println("Valid Heading")8 } else {9 fmt.Println("Invalid Heading")10 }11}

Full Screen

Full Screen

Heading

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the string")4 fmt.Scanln(&str)5 fmt.Println(validations.Heading(str))6}

Full Screen

Full Screen

Heading

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 valid := regexp.MustCompile(`\A[A-Z][a-z]+[ ]+[A-Z][a-z]+\z`)4 fmt.Println(valid.MatchString("James Bond"))5 fmt.Println(valid.MatchString("James bond"))6 fmt.Println(valid.MatchString("james Bond"))7 fmt.Println(valid.MatchString("james bond"))8 fmt.Println(valid.MatchString("James Bond "))9 fmt.Println(valid.MatchString(" James Bond"))10}

Full Screen

Full Screen

Heading

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the string to be validated")4 fmt.Scanln(&input)5 regex = "^[A-Z]{1}[a-z]{2,}$"6 result = Heading(input, regex)7 fmt.Println(result)8}9type validation struct {10}11func (v validation) Heading(input string, regex string) bool {12 heading := regexp.MustCompile(regex)13 result := heading.MatchString(input)14}15var Heading = validation{}.Heading

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful