mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Add more tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix remaining tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix more lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix more lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix the final lint issue. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package create
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFmtfn(t *testing.T) {
|
|
tests := []struct {
|
|
d int
|
|
n string
|
|
t string
|
|
expected string
|
|
}{
|
|
{0, "1", "test", color.GreenString("[1]") + " test "},
|
|
{2, "2", "example", " " + color.GreenString("[2]") + " example "},
|
|
{4, "3", "sample", " " + color.GreenString("[3]") + " sample "},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.n, func(t *testing.T) {
|
|
result := fmtfn(tt.d, tt.n, tt.t)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestExtractHostname(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for in, out := range map[string]string{
|
|
"": "",
|
|
"http://www.example.org/": "www.example.org",
|
|
"++#+++#jhlkadsrezu 33 553q ++++##$§&": "jhlkadsrezu_33_553q",
|
|
"www.example.org/?foo=bar#abc": "www.example.org",
|
|
"a test": "a_test",
|
|
"http://example.com": "example.com",
|
|
"https://sub.example.com": "sub.example.com",
|
|
"ftp://example.com": "example.com",
|
|
"example.com": "example.com",
|
|
"invalid-url": "invalid-url",
|
|
} {
|
|
assert.Equal(t, out, extractHostname(in))
|
|
}
|
|
}
|