You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
64 lines
1.1 KiB
package key_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"gitoa.ru/go-4devs/config"
|
|
"gitoa.ru/go-4devs/config/key"
|
|
)
|
|
|
|
func TestLastIndex(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
|
|
cases := map[string]struct {
|
|
sep string
|
|
path string
|
|
field string
|
|
}{
|
|
"/secret/with/field/name": {
|
|
sep: "/",
|
|
path: "/secret/with/field",
|
|
field: "name",
|
|
},
|
|
"/secret/database:username": {
|
|
sep: ":",
|
|
path: "/secret/database",
|
|
field: "username",
|
|
},
|
|
"database:username": {
|
|
sep: ":",
|
|
path: "database",
|
|
field: "username",
|
|
},
|
|
"/secret/database-dsn": {
|
|
sep: ":",
|
|
path: "/secret/database-dsn",
|
|
field: "",
|
|
},
|
|
"/secret/database--dsn": {
|
|
sep: "--",
|
|
path: "/secret/database",
|
|
field: "dsn",
|
|
},
|
|
"/secret/database:dsn": {
|
|
sep: "--",
|
|
path: "/secret/database:dsn",
|
|
field: "",
|
|
},
|
|
}
|
|
|
|
for path, data := range cases {
|
|
k := config.Key{
|
|
Name: path,
|
|
}
|
|
|
|
fn := key.LastIndex(data.sep, key.Name)
|
|
ns, field := fn(ctx, k)
|
|
assert.Equal(t, data.field, field, k)
|
|
assert.Equal(t, data.path, ns, k)
|
|
}
|
|
}
|
|
|