Merge "[OOM-CERT-SERVICE] Add change-log"
[oom/platform/cert-service.git] / certServiceK8sExternalProvider / main_test.go
1 /*
2  * ============LICENSE_START=======================================================
3  * oom-certservice-k8s-external-provider
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package main
22
23 import (
24         "flag"
25         "os"
26         "testing"
27
28         "github.com/stretchr/testify/assert"
29 )
30
31 func Test_shouldParseArguments_defaultValues(t *testing.T) {
32         os.Args = []string{
33                 "first-arg-is-omitted-by-method-parse-arguments-so-this-only-a-placeholder"}
34         flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
35
36         metricsAddr, logLevel, enableLeaderElection := parseInputArguments()
37
38         assert.Equal(t, ":8080", metricsAddr)
39         assert.Equal(t, "debug", logLevel)
40         assert.False(t, enableLeaderElection)
41 }
42
43 func Test_shouldParseArguments_valuesFromCLI(t *testing.T) {
44         os.Args = []string{
45                 "first-arg-is-omitted-by-method-parse-arguments-so-this-only-a-placeholder",
46                 "--metrics-addr=127.0.0.1:555",
47                 "--log-level=error",
48                 "--enable-leader-election=true"}
49         flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
50
51         metricsAddr, logLevel, enableLeaderElection := parseInputArguments()
52
53         assert.Equal(t, "127.0.0.1:555", metricsAddr)
54         assert.Equal(t, "error", logLevel)
55         assert.True(t, enableLeaderElection)
56 }