github.com/newrelic/go-agent@v3.26.0+incompatible/internal/environment_test.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package internal
     5  
     6  import (
     7  	"encoding/json"
     8  	"runtime"
     9  	"testing"
    10  )
    11  
    12  func TestMarshalEnvironment(t *testing.T) {
    13  	js, err := json.Marshal(&SampleEnvironment)
    14  	if nil != err {
    15  		t.Fatal(err)
    16  	}
    17  	expect := CompactJSONString(`[
    18  		["runtime.Compiler","comp"],
    19  		["runtime.GOARCH","arch"],
    20  		["runtime.GOOS","goos"],
    21  		["runtime.Version","vers"],
    22  		["runtime.NumCPU",8]]`)
    23  	if string(js) != expect {
    24  		t.Fatal(string(js))
    25  	}
    26  }
    27  
    28  func TestEnvironmentFields(t *testing.T) {
    29  	env := NewEnvironment()
    30  	if env.Compiler != runtime.Compiler {
    31  		t.Error(env.Compiler, runtime.Compiler)
    32  	}
    33  	if env.GOARCH != runtime.GOARCH {
    34  		t.Error(env.GOARCH, runtime.GOARCH)
    35  	}
    36  	if env.GOOS != runtime.GOOS {
    37  		t.Error(env.GOOS, runtime.GOOS)
    38  	}
    39  	if env.Version != runtime.Version() {
    40  		t.Error(env.Version, runtime.Version())
    41  	}
    42  	if env.NumCPU != runtime.NumCPU() {
    43  		t.Error(env.NumCPU, runtime.NumCPU())
    44  	}
    45  }