github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/com/sap/piper/k8s/SystemEnvTest.groovy (about)

     1  package com.sap.piper.k8s
     2  
     3  import com.sap.piper.k8s.SystemEnv
     4  import org.junit.Before
     5  import org.junit.Test
     6  
     7  import static org.junit.Assert.assertEquals
     8  import static org.junit.Assert.assertNotNull
     9  
    10  class SystemEnvTest {
    11      SystemEnv env = null
    12      Map systemEnvironmentMock = [:]
    13      @Before
    14      void setUp() {
    15          systemEnvironmentMock = ['HTTP_PROXY' : 'http://my-http-proxy:8080',
    16                                   'HTTPS_PROXY': 'http://my-http-proxy:8080',
    17                                   'NO_PROXY'   : '*.example.com,localhost',
    18                                   'http_proxy' : 'http://my-http-proxy:8080',
    19                                   'https_proxy': 'http://my-http-proxy:8080',
    20                                   'no_proxy'   : '*.example.com,localhost',]
    21          System.metaClass.static.getenv = { String s -> return systemEnvironmentMock.get(s) }
    22          env = new SystemEnv()
    23      }
    24  
    25      @Test
    26      void testget() {
    27          String name = 'HTTP_PROXY'
    28          assertEquals(systemEnvironmentMock.get(name), env.get(name))
    29  
    30          name = 'HTTPS_PROXY'
    31          assertEquals(systemEnvironmentMock.get(name), env.get(name))
    32  
    33      }
    34  
    35      @Test
    36      void testgetEnv() {
    37          assertNotNull(env)
    38          assertEquals(systemEnvironmentMock.keySet(), env.getEnv().keySet())
    39      }
    40  
    41      @Test
    42      void testremove() {
    43          String name = 'HTTP_PROXY'
    44          env.remove(name)
    45          assertEquals(env.getEnv().containsKey(name),false)
    46      }
    47  }