Files
gluetun/internal/models/markdown_test.go

68 lines
1.7 KiB
Go
Raw Normal View History

2021-09-23 13:13:17 +00:00
package models
import (
"testing"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
2021-09-23 13:13:17 +00:00
"github.com/stretchr/testify/assert"
)
func Test_Servers_ToMarkdown(t *testing.T) {
2021-09-23 13:13:17 +00:00
t.Parallel()
testCases := map[string]struct {
provider string
servers Servers
formatted string
errWrapped error
errMessage string
}{
"unsupported_provider": {
provider: "unsupported",
errWrapped: ErrMarkdownHeadersNotDefined,
errMessage: "getting markdown headers: markdown headers not defined: for unsupported",
},
providers.Cyberghost: {
provider: providers.Cyberghost,
servers: Servers{
Servers: []Server{
{Country: "a", UDP: true, Hostname: "xa"},
{Country: "b", TCP: true, Hostname: "xb"},
},
},
formatted: "| Country | Hostname | TCP | UDP |\n" +
"| --- | --- | --- | --- |\n" +
"| a | `xa` | ❌ | ✅ |\n" +
"| b | `xb` | ✅ | ❌ |\n",
},
providers.Fastestvpn: {
provider: providers.Fastestvpn,
servers: Servers{
Servers: []Server{
{Country: "a", Hostname: "xa", VPN: vpn.OpenVPN, TCP: true},
{Country: "b", Hostname: "xb", VPN: vpn.OpenVPN, UDP: true},
},
},
formatted: "| Country | Hostname | VPN | TCP | UDP |\n" +
"| --- | --- | --- | --- | --- |\n" +
"| a | `xa` | openvpn | ✅ | ❌ |\n" +
"| b | `xb` | openvpn | ❌ | ✅ |\n",
2021-09-23 13:13:17 +00:00
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()
2021-09-23 13:13:17 +00:00
markdown, err := testCase.servers.toMarkdown(testCase.provider)
2021-09-23 13:13:17 +00:00
assert.Equal(t, testCase.formatted, markdown)
assert.ErrorIs(t, err, testCase.errWrapped)
if testCase.errWrapped != nil {
assert.EqualError(t, err, testCase.errMessage)
}
})
2021-09-23 13:13:17 +00:00
}
}