From 73767dcd250635b4179f017b0061a20218e17d7b Mon Sep 17 00:00:00 2001 From: Gulsum Atici Date: Thu, 4 Apr 2024 19:28:44 +0300 Subject: [PATCH] chore: Adding unit tests for custom Webui URL (#74) * Adding unit tests for custom Webui URL Signed-off-by: gatici * Update udr_config_with_custom_webui_url.yaml --------- Signed-off-by: gatici Co-authored-by: gab-arrobo --- factory/config.example.yaml | 1 - factory/udr_config_test.go | 34 +++++++++++++++++++ factory/udr_config_with_custom_webui_url.yaml | 19 +++++++++++ go.mod | 3 ++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 factory/udr_config_test.go create mode 100644 factory/udr_config_with_custom_webui_url.yaml diff --git a/factory/config.example.yaml b/factory/config.example.yaml index 5d222e2..fcbead4 100644 --- a/factory/config.example.yaml +++ b/factory/config.example.yaml @@ -17,7 +17,6 @@ configuration: url: http://dummy authKeysDbName: authentication authUrl: http://dummy - webuiUri: webui:9876 plmnSupportList: - plmnId: mcc: "208" diff --git a/factory/udr_config_test.go b/factory/udr_config_test.go new file mode 100644 index 0000000..efad6a8 --- /dev/null +++ b/factory/udr_config_test.go @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2024 Canonical Ltd. +/* + * Tests for UDR Configuration Factory + */ + +package factory + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +// Webui URL is not set then default Webui URL value is returned +func TestGetDefaultWebuiUrl(t *testing.T) { + if err := InitConfigFactory("config.example.yaml"); err != nil { + fmt.Printf("Error in InitConfigFactory: %v\n", err) + } + got := UdrConfig.Configuration.WebuiUri + want := "webui:9876" + assert.Equal(t, got, want, "The webui URL is not correct.") +} + +// Webui URL is set to a custom value then custom Webui URL is returned +func TestGetCustomWebuiUrl(t *testing.T) { + if err := InitConfigFactory("udr_config_with_custom_webui_url.yaml"); err != nil { + fmt.Printf("Error in InitConfigFactory: %v\n", err) + } + got := UdrConfig.Configuration.WebuiUri + want := "myspecialwebui:9872" + assert.Equal(t, got, want, "The webui URL is not correct.") +} diff --git a/factory/udr_config_with_custom_webui_url.yaml b/factory/udr_config_with_custom_webui_url.yaml new file mode 100644 index 0000000..ef46603 --- /dev/null +++ b/factory/udr_config_with_custom_webui_url.yaml @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2024 Canonical Ltd. + +info: + version: 1.0.0 + description: UDR initial local configuration + +configuration: + webuiUri: myspecialwebui:9872 # a valid URI of Webui + sbi: # Service Based Interface + scheme: https + registerIPv4: 127.0.0.4 + bindingIPv4: 0.0.0.0 + port: 8000 + mongodb: + name: free5gc + url: http://dummy + authKeysDbName: authentication + authUrl: http://dummy diff --git a/go.mod b/go.mod index c6778f4..d6af989 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/omec-project/openapi v1.2.0 github.com/omec-project/util v1.0.13 github.com/sirupsen/logrus v1.9.3 + github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.14 go.mongodb.org/mongo-driver v1.10.1 gopkg.in/yaml.v2 v2.4.0 @@ -25,6 +26,7 @@ require ( github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect @@ -46,6 +48,7 @@ require ( github.com/omec-project/logger_conf v1.1.1 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect