gluetun/internal/models/markdown_test.go
Quentin McGaw abe9dcbe33 chore(lint): add new linters and update codebase
- add canonicalheader
- add copyloopvar
- add fatcontext
- add intrange
2024-10-11 18:28:00 +00:00

68 lines
1.7 KiB
Go

package models
import (
"testing"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/stretchr/testify/assert"
)
func Test_Servers_ToMarkdown(t *testing.T) {
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",
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()
markdown, err := testCase.servers.toMarkdown(testCase.provider)
assert.Equal(t, testCase.formatted, markdown)
assert.ErrorIs(t, err, testCase.errWrapped)
if testCase.errWrapped != nil {
assert.EqualError(t, err, testCase.errMessage)
}
})
}
}