- simple test for helper function

This commit is contained in:
naudachu 2023-06-21 21:03:48 +05:00
parent 7221fa4aad
commit 9a670fdc61
2 changed files with 40 additions and 5 deletions

View File

@ -1,7 +1,9 @@
package helpers package helpers
import ( import (
"encoding/xml"
"regexp" "regexp"
"strconv"
"strings" "strings"
) )
@ -22,3 +24,37 @@ func GitNaming(input string) string {
// Join words and return // Join words and return
return strings.Join(words, "-") return strings.Join(words, "-")
} }
type MultistatusObj struct {
XMLName xml.Name `xml:"multistatus"`
Multistatus struct {
XMLName xml.Name `xml:"response"`
Propstat struct {
XMLName xml.Name `xml:"propstat"`
Prop struct {
XMLName xml.Name `xml:"prop"`
FileID struct {
XMLName xml.Name `xml:"fileid"`
ID string `xml:",chardata"`
}
}
}
}
}
func GetFileIDFromRespBody(str []byte) int {
var multi MultistatusObj
err := xml.Unmarshal(str, &multi)
if err != nil {
return 0
}
id, err := strconv.Atoi(multi.Multistatus.Propstat.Prop.FileID.ID)
if err != nil {
return 0
}
return id
}

View File

@ -1,7 +1,6 @@
package ext package helpers
import ( import (
"log"
"testing" "testing"
) )
@ -12,7 +11,7 @@ const (
// [ ] todo normal test... // [ ] todo normal test...
func TestGetFileID(t *testing.T) { func TestGetFileID(t *testing.T) {
str, err := getFileIDFromRespBody([]byte(EXAMPLE)) if output := GetFileIDFromRespBody([]byte(EXAMPLE)); output != 33225 {
log.Print(str, err) t.Errorf("Output %q not equal to expected %q", output, 33225)
}
} }