mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-04 13:36:35 +02:00
internal/controld: add support for parsing client id from raw UID
This commit is contained in:
@@ -1,34 +1,31 @@
|
||||
//go:build controld
|
||||
|
||||
package controld
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFetchResolverConfig(t *testing.T) {
|
||||
func Test_parseUID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
uid string
|
||||
dev bool
|
||||
wantErr bool
|
||||
name string
|
||||
uid string
|
||||
wantUID string
|
||||
wantClientID string
|
||||
}{
|
||||
{"valid com", "p2", false, false},
|
||||
{"valid dev", "p2", true, false},
|
||||
{"invalid uid", "abcd1234", false, true},
|
||||
{"empty", "", "", ""},
|
||||
{"only uid", "abcd1234", "abcd1234", ""},
|
||||
{"with client id", "abcd1234/clientID", "abcd1234", "clientID"},
|
||||
{"with empty clientID", "abcd1234/", "abcd1234", ""},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := FetchResolverConfig(tc.uid, "dev-test", tc.dev)
|
||||
require.False(t, (err != nil) != tc.wantErr, err)
|
||||
if !tc.wantErr {
|
||||
assert.NotEmpty(t, got.DOH)
|
||||
}
|
||||
gotUID, gotClientID := ParseRawUID(tc.uid)
|
||||
assert.Equal(t, tc.wantUID, gotUID)
|
||||
assert.Equal(t, tc.wantClientID, gotClientID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user