Skip to content
Snippets Groups Projects
Select Git revision
  • dadf1ef4afcfd0f7f0e09f68ff6f4b88ad23209d
  • main default protected
  • ozg-8323-umzug-dependency-track
  • OZG-8252-gitlab-pipelines
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • 2.27.0
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
41 results

vorgang.service.ts

Blame
  • config_test.go 3.82 KiB
    /*
     * Copyright (C) 2023-2024
     * Das Land Schleswig-Holstein vertreten durch den
     * Ministerpräsidenten des Landes Schleswig-Holstein
     * Staatskanzlei
     * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
     *
     * Lizenziert unter der EUPL, Version 1.2 oder - sobald
     * diese von der Europäischen Kommission genehmigt wurden -
     * Folgeversionen der EUPL ("Lizenz");
     * Sie dürfen dieses Werk ausschließlich gemäß
     * dieser Lizenz nutzen.
     * Eine Kopie der Lizenz finden Sie hier:
     *
     * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
     *
     * Sofern nicht durch anwendbare Rechtsvorschriften
     * gefordert oder in schriftlicher Form vereinbart, wird
     * die unter der Lizenz verbreitete Software "so wie sie
     * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
     * ausdrücklich oder stillschweigend - verbreitet.
     * Die sprachspezifischen Genehmigungen und Beschränkungen
     * unter der Lizenz sind dem Lizenztext zu entnehmen.
     */
    
    package config
    
    import (
    	"os"
    	"testing"
    
    	"github.com/stretchr/testify/assert"
    )
    
    func TestLoadConfig(t *testing.T) {
    	t.Run("should load config from file", func(t *testing.T) {
    		config := LoadConfig()
    
    		expectedConfig := Config{}
    		expectedConfig.Http.Server.Port = 8080
    		expectedConfig.Grpc.Collaboration.Server.Port = 50052
    		expectedConfig.Grpc.Collaboration.Router.Port = 50051
    		expectedConfig.Grpc.Registration.Server.Url = "localhost:50052"
    		expectedConfig.Grpc.Mock = false
    		expectedConfig.Logging.Level = "DEBUG"
    
    		assert.Equal(t, expectedConfig, config)
    	})
    
    	t.Run("should load config from env", func(t *testing.T) {
    		envVars := map[string]string{
    			"HTTP_SERVER_PORT":               "9090",
    			"GRPC_COLLABORATION_SERVER_PORT": "50052",
    			"GRPC_COLLABORATION_ROUTER_PORT": "50051",
    			"GRPC_REGISTRATION_SERVER_URL":   "localhost:99999",
    			"LOGGING_LEVEL":                  "ERROR",
    		}
    
    		for key, value := range envVars {
    			assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
    		}
    
    		config := LoadConfig("testdata/empty_test_config.yml")
    
    		for key := range envVars {
    			assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
    		}
    
    		expectedConfig := Config{}
    		expectedConfig.Http.Server.Port = 9090
    		expectedConfig.Grpc.Collaboration.Server.Port = 50052
    		expectedConfig.Grpc.Collaboration.Router.Port = 50051
    		expectedConfig.Grpc.Registration.Server.Url = "localhost:99999"
    		expectedConfig.Grpc.Mock = false
    		expectedConfig.Logging.Level = "ERROR"
    
    		assert.Equal(t, expectedConfig, config)
    	})
    
    	t.Run("should overwrite config with env", func(t *testing.T) {
    		envVars := map[string]string{
    			"HTTP_SERVER_PORT":             "9090",
    			"GRPC_REGISTRATION_SERVER_URL": "localhost:99999",
    		}
    
    		for key, value := range envVars {
    			assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
    		}
    
    		config := LoadConfig()
    
    		for key := range envVars {
    			assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
    		}
    
    		expectedConfig := Config{}
    		expectedConfig.Http.Server.Port = 9090
    		expectedConfig.Grpc.Collaboration.Server.Port = 50052
    		expectedConfig.Grpc.Collaboration.Router.Port = 50051
    		expectedConfig.Grpc.Registration.Server.Url = "localhost:99999"
    		expectedConfig.Grpc.Mock = false
    		expectedConfig.Logging.Level = "DEBUG"
    
    		assert.Equal(t, expectedConfig, config)
    	})
    }
    
    func TestValidateGrpcUrl(t *testing.T) {
    	testData := []struct {
    		grpcUrl        string
    		expectedResult bool
    	}{
    		{"localhost:56789", true},
    		{"test.example.com:20", true},
    		{"invalidUrl", false},
    		{"%test%:2345", false},
    		{"localhost:234567", false},
    		{"example.com:", false},
    		{":6789", false},
    		{"example..com:8080", false},
    		{"example.com:abc", false},
    	}
    
    	for _, data := range testData {
    		result := ValidateGrpcUrl(data.grpcUrl)
    
    		assert.Equal(t, data.expectedResult, result)
    	}
    }