- simple test for helper function
This commit is contained in:
parent
7221fa4aad
commit
9a670fdc61
|
|
@ -1,7 +1,9 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -22,3 +24,37 @@ func GitNaming(input string) string {
|
|||
// Join words and return
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package ext
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -12,7 +11,7 @@ const (
|
|||
// [ ] todo normal test...
|
||||
func TestGetFileID(t *testing.T) {
|
||||
|
||||
str, err := getFileIDFromRespBody([]byte(EXAMPLE))
|
||||
log.Print(str, err)
|
||||
|
||||
if output := GetFileIDFromRespBody([]byte(EXAMPLE)); output != 33225 {
|
||||
t.Errorf("Output %q not equal to expected %q", output, 33225)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue