github.com/jeffalder/nr.yml/v3@v3.0.1-0.20200721182236-9572b92f5925/nr_yml/utilization_test.go (about)

     1  //   Copyright 2020, Jeff Alder
     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  package nr_yml
    15  
    16  import (
    17  	"fmt"
    18  	"github.com/newrelic/go-agent/v3/newrelic"
    19  	"github.com/stretchr/testify/assert"
    20  	"testing"
    21  )
    22  
    23  func TestUtilizationAll(t *testing.T) {
    24  	withContents(`
    25  production:
    26    utilization:
    27      billing_hostname: host123
    28      total_ram_mib: 2344
    29      logical_processors: 15
    30  `, t, func(filename string, t *testing.T) {
    31  		cfg := new(newrelic.Config)
    32  		ConfigFromYamlFile(filename)(cfg)
    33  		if cfg.Error != nil {
    34  			t.Fatal("specified env should not generate error", cfg.Error)
    35  		}
    36  		assert.Equal(t, "host123", cfg.Utilization.BillingHostname)
    37  		assert.Equal(t, 2344, cfg.Utilization.TotalRAMMIB)
    38  		assert.Equal(t, 15, cfg.Utilization.LogicalProcessors)
    39  	})
    40  }
    41  
    42  func TestDetectClouds(t *testing.T) {
    43  	for _, cloud := range [...]string{"aws", "azure", "docker", "gcp", "kubernetes", "pcf"} {
    44  		withContents(fmt.Sprintf(`
    45  production:
    46    utilization:
    47      detect_%s: true
    48  `, cloud), t, func(filename string, t *testing.T) {
    49  			cfg := new(newrelic.Config)
    50  			ConfigFromYamlFile(filename)(cfg)
    51  			assert.Equal(t, cloud == "aws", cfg.Utilization.DetectAWS)
    52  			assert.Equal(t, cloud == "azure", cfg.Utilization.DetectAzure)
    53  			assert.Equal(t, cloud == "docker", cfg.Utilization.DetectDocker)
    54  			assert.Equal(t, cloud == "gcp", cfg.Utilization.DetectGCP)
    55  			assert.Equal(t, cloud == "kubernetes", cfg.Utilization.DetectKubernetes)
    56  			assert.Equal(t, cloud == "pcf", cfg.Utilization.DetectPCF)
    57  		})
    58  	}
    59  }
    60