github.com/palantir/witchcraft-go-server/v2@v2.76.0/config/install_test.go (about)

     1  // Copyright (c) 2019 Palantir Technologies. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  	"gopkg.in/yaml.v2"
    23  )
    24  
    25  func TestInstallConfig(t *testing.T) {
    26  	conf := `
    27  product-name: productName
    28  trace-sample-rate: 0.5
    29  management-trace-sample-rate: 0.6
    30  use-console-log: true
    31  metrics-emit-frequency: 1s
    32  server:
    33    address: address
    34    port: 10
    35    management-port: 11
    36    context-path: ContextPath
    37    client-ca-files:
    38      - a
    39      - b
    40    cert-file: certFile
    41    key-file: keyFile
    42  `
    43  	var install Install
    44  	err := yaml.Unmarshal([]byte(conf), &install)
    45  	assert.NoError(t, err)
    46  	assert.Equal(t, Install{
    47  		ProductName: "productName",
    48  		Server: Server{
    49  			Address:        "address",
    50  			Port:           10,
    51  			ManagementPort: 11,
    52  			ContextPath:    "ContextPath",
    53  			ClientCAFiles:  []string{"a", "b"},
    54  			CertFile:       "certFile",
    55  			KeyFile:        "keyFile",
    56  		},
    57  		MetricsEmitFrequency:      time.Second,
    58  		TraceSampleRate:           asFloat(0.5),
    59  		ManagementTraceSampleRate: asFloat(0.6),
    60  		UseConsoleLog:             true,
    61  	}, install)
    62  }
    63  
    64  func asFloat(f float64) *float64 {
    65  	return &f
    66  }