github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/environment_test.go (about)

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