tests/teplates_reserch/main_test.go

48 lines
1.4 KiB
Go

package main
import (
"fmt"
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)
func TestTemplateToken(t *testing.T) {
for name, tt := range map[string]struct {
inTemplate string
outToken string
outError error
}{
"Normal string": {
inTemplate: "https://cloud.dev8.on-premise.ru/shared/incoming/?token=oG9Z9Ej9k6hhNu2R2U9MZz9undYTuDstbsaTxQSLA7ZDPM5XY5iDnzm79S8x7gSi&action=accept",
outToken: "oG9Z9Ej9k6hhNu2R2U9MZz9undYTuDstbsaTxQSLA7ZDPM5XY5iDnzm79S8x7gSi",
outError: nil,
},
"No URI": {
inTemplate: "?token=oG9Z9Ej9k6hhNu2R2U9MZz9undYTuDstbsaTxQSLA7ZDPM5XY5iDnzm79S8x7gSi&action=accept",
outToken: "oG9Z9Ej9k6hhNu2R2U9MZz9undYTuDstbsaTxQSLA7ZDPM5XY5iDnzm79S8x7gSi",
outError: nil,
},
"No token": {
inTemplate: "https://cloud.dev8.on-premise.ru/shared/incoming/?action=accept",
outToken: "",
outError: errNoToken,
},
"Insane string": {
inTemplate: "<MNbv&c656NGH,(omGNCFBU6XFNGMl<jmkntBF7JI6uh<mFNb^u%dfhgh HCVvrtdrfjFDyf#%$gehrj&KYHJ7IHDRTyu",
outToken: "",
outError: &url.Error{Op: "parse", URL: "<MNbv&c656NGH,(omGNCFBU6XFNGMl<jmkntBF7JI6uh<mFNb^u%dfhgh HCVvrtdrfjFDyf#%$gehrj&KYHJ7IHDRTyu", Err: url.EscapeError("%$g")},
},
} {
t.Run(fmt.Sprintf("SegmentedTemplate: %s", name), func(t *testing.T) {
out, err := TemplateToken(tt.inTemplate)
assert.Equal(t, tt.outToken, out)
assert.Equal(t, tt.outError, err)
})
}
}
func TestTemplateAction(t *testing.T) {
}