feat(GODT-3121): added options to kb-tester CLI tool.

This commit is contained in:
Xavier Michelon
2023-12-08 09:59:04 +01:00
parent 789c1cc816
commit 416f696863
4 changed files with 136 additions and 28 deletions

View File

@ -4,8 +4,7 @@
"url": "https://proton.me/support/automatically-start-bridge",
"title": "Automatically start Bridge",
"keywords": [
"start",
"automatically",
"automatic",
"login",
"start",
"boot"
@ -53,7 +52,8 @@
"title": "Proton Mail Bridge connection issues with Thunderbird, Outlook, and Apple Mail",
"keywords": [
"connect",
"error",
"SSL",
"STARTTLS",
"client",
"program",
"Outlook",
@ -68,7 +68,8 @@
"keywords": [
"pgp",
"gpg",
"encrypt"
"encrypt",
"crypto"
]
},
{
@ -205,7 +206,6 @@
"Outlook",
"configure",
"setup",
"program",
"application",
"setup",
"IMAP",

View File

@ -52,14 +52,20 @@ func GetArticleList() (ArticleList, error) {
return articles, err
}
// GetSuggestions return a list of up to 3 suggestions for KB articles matching the given user input.
// GetSuggestions returns a list of up to 3 suggestions for the built-in list of KB articles matching the given user input.
func GetSuggestions(userInput string) (ArticleList, error) {
userInput = strings.ToUpper(userInput)
articles, err := GetArticleList()
if err != nil {
return ArticleList{}, err
}
return GetSuggestionsFromArticleList(userInput, articles)
}
// GetSuggestionsFromArticleList returns a list of up to 3 suggestions for the given list of KB articles matching the given user input.
func GetSuggestionsFromArticleList(userInput string, articles ArticleList) (ArticleList, error) {
userInput = strings.ToUpper(userInput)
for _, article := range articles {
for _, keyword := range article.Keywords {
if strings.Contains(userInput, strings.ToUpper(keyword)) {
@ -78,7 +84,7 @@ func GetSuggestions(userInput string) (ArticleList, error) {
return articles, nil
}
// GetArticleIndex retrieve the index of an article from its url. if the article is not found, ErrArticleNotFound is returned.
// GetArticleIndex retrieves the index of an article from its url. if the article is not found, ErrArticleNotFound is returned.
func GetArticleIndex(url string) (uint64, error) {
articles, err := GetArticleList()
if err != nil {

View File

@ -18,7 +18,6 @@
package kb
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
@ -42,16 +41,39 @@ func Test_ArticleList(t *testing.T) {
func Test_GetSuggestions(t *testing.T) {
suggestions, err := GetSuggestions("Thunderbird is not working, error during password")
require.NoError(t, err)
require.True(t, len(suggestions) <= 3)
for _, article := range suggestions {
fmt.Printf("Score: %v - %#v\n", article.Score, article.Title)
}
count := len(suggestions)
require.True(t, (count > 0) && (count <= 3))
suggestions, err = GetSuggestions("Supercalifragilisticexpialidocious Sesquipedalian Worcestershire")
require.NoError(t, err)
require.Empty(t, suggestions)
}
func Test_GetSuggestionsFromArticleList(t *testing.T) {
articleList := ArticleList{}
suggestions, err := GetSuggestionsFromArticleList("Thunderbird", articleList)
require.NoError(t, err)
require.Empty(t, suggestions)
articleList = ArticleList{
&Article{
Index: 0,
URL: "https://proton.me",
Title: "Proton home page",
Keywords: []string{"proton"},
},
&Article{
Index: 1,
URL: "https://mozilla.org",
Title: "Mozilla home page",
Keywords: []string{"mozilla"},
},
}
suggestions, err = GetSuggestionsFromArticleList("PRoToN", articleList)
require.NoError(t, err)
require.Len(t, suggestions, 1)
require.Equal(t, suggestions[0].URL, "https://proton.me")
}
func Test_GetArticleIndex(t *testing.T) {
index1, err := GetArticleIndex("https://proton.me/support/bridge-for-linux")
require.NoError(t, err)