...

Source file src/github.com/datawire/ambassador/v2/pkg/agent/report_test.go

Documentation: github.com/datawire/ambassador/v2/pkg/agent

     1  package agent_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/datawire/ambassador/v2/pkg/agent"
     9  	agentTypes "github.com/datawire/ambassador/v2/pkg/api/agent"
    10  	snapshotTypes "github.com/datawire/ambassador/v2/pkg/snapshot/v1"
    11  )
    12  
    13  func TestGetIdentity(t *testing.T) {
    14  	defaultHost := "defaulthost"
    15  	getIdentityTests := []struct {
    16  		testName         string
    17  		cfg              *snapshotTypes.AmbassadorMetaInfo
    18  		expectedIdentity *agentTypes.Identity
    19  		hostname         *string
    20  	}{
    21  		{
    22  			// GetIdentity should copy info from the ambassador meta to populate the
    23  			// Identity
    24  			testName: "basic",
    25  			expectedIdentity: &agentTypes.Identity{
    26  				Label:     "",
    27  				ClusterId: "reallyspecialclusterid",
    28  				Version:   "",
    29  				Hostname:  defaultHost,
    30  			},
    31  			cfg: &snapshotTypes.AmbassadorMetaInfo{
    32  				ClusterID:         "reallyspecialclusterid",
    33  				AmbassadorVersion: "v1.0",
    34  			},
    35  		},
    36  		{
    37  			// if our config is nil, GetIdentity should return nil
    38  			testName:         "nil-config",
    39  			expectedIdentity: nil,
    40  			cfg:              nil,
    41  		},
    42  		{
    43  			// If the meta info doesn't contain any identifying info, GetIdenity should
    44  			// return nil
    45  			testName:         "empty-cepc",
    46  			expectedIdentity: nil,
    47  			cfg: &snapshotTypes.AmbassadorMetaInfo{
    48  				ClusterID:         "",
    49  				AmbassadorVersion: "v1.0",
    50  			},
    51  		},
    52  	}
    53  	for _, testcase := range getIdentityTests {
    54  		t.Run(testcase.testName, func(innerT *testing.T) {
    55  			var host string
    56  			if testcase.hostname == nil {
    57  				host = defaultHost
    58  			} else {
    59  				host = *testcase.hostname
    60  			}
    61  			identity := agent.GetIdentity(testcase.cfg, host)
    62  
    63  			assert.Equal(innerT, testcase.expectedIdentity, identity)
    64  		})
    65  	}
    66  }
    67  

View as plain text