mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add new unit tests on migrator
This commit is contained in:
committed by
Dan Christian Bogos
parent
99e278040e
commit
5e5d615aad
@@ -316,3 +316,62 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAliasV1AliasSetId(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expectedValues v1Alias
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
input: "dir:cgrates.org:category:1001:subject:context",
|
||||
expectedValues: v1Alias{
|
||||
Direction: "dir",
|
||||
Tenant: "cgrates.org",
|
||||
Category: "category",
|
||||
Account: "1001",
|
||||
Subject: "subject",
|
||||
Context: "context",
|
||||
},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
input: "invalidKeyFormat",
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
alias := &v1Alias{}
|
||||
err := alias.SetId(tt.input)
|
||||
|
||||
if tt.expectError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error but got none")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error but got %v", err)
|
||||
}
|
||||
if alias.Direction != tt.expectedValues.Direction {
|
||||
t.Errorf("SetId() Direction = %v, want %v", alias.Direction, tt.expectedValues.Direction)
|
||||
}
|
||||
if alias.Tenant != tt.expectedValues.Tenant {
|
||||
t.Errorf("SetId() Tenant = %v, want %v", alias.Tenant, tt.expectedValues.Tenant)
|
||||
}
|
||||
if alias.Category != tt.expectedValues.Category {
|
||||
t.Errorf("SetId() Category = %v, want %v", alias.Category, tt.expectedValues.Category)
|
||||
}
|
||||
if alias.Account != tt.expectedValues.Account {
|
||||
t.Errorf("SetId() Account = %v, want %v", alias.Account, tt.expectedValues.Account)
|
||||
}
|
||||
if alias.Subject != tt.expectedValues.Subject {
|
||||
t.Errorf("SetId() Subject = %v, want %v", alias.Subject, tt.expectedValues.Subject)
|
||||
}
|
||||
if alias.Context != tt.expectedValues.Context {
|
||||
t.Errorf("SetId() Context = %v, want %v", alias.Context, tt.expectedValues.Context)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,3 +213,46 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserV1UserProfileGetId(t *testing.T) {
|
||||
profile := &v1UserProfile{
|
||||
Tenant: "cgrates.org",
|
||||
UserName: "1001",
|
||||
}
|
||||
expected := "cgrates.org:1001"
|
||||
actual := profile.GetId()
|
||||
if actual != expected {
|
||||
t.Errorf("GetId() = %v, want %v", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserV1UserProfileSetId(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expectedTenant string
|
||||
expectedUserName string
|
||||
expectError bool
|
||||
}{
|
||||
{"cgrates.org:1001", "cgrates.org", "1001", false},
|
||||
{"invalidKeyFormat", "", "", true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
profile := &v1UserProfile{}
|
||||
err := profile.SetId(tt.input)
|
||||
if tt.expectError {
|
||||
if err == nil {
|
||||
t.Errorf("SetId(%q) expected error but got none", tt.input)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("SetId(%q) unexpected error: %v", tt.input, err)
|
||||
}
|
||||
if profile.Tenant != tt.expectedTenant {
|
||||
t.Errorf("SetId(%q) Tenant = %v, want %v", tt.input, profile.Tenant, tt.expectedTenant)
|
||||
}
|
||||
if profile.UserName != tt.expectedUserName {
|
||||
t.Errorf("SetId(%q) UserName = %v, want %v", tt.input, profile.UserName, tt.expectedUserName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user