github.phpd.cn/hashicorp/packer@v1.3.2/builder/azure/arm/authenticate_test.go (about)

     1  package arm
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/Azure/go-autorest/autorest/azure"
     7  )
     8  
     9  // Behavior is the most important thing to assert for ServicePrincipalToken, but
    10  // that cannot be done in a unit test because it involves network access.  Instead,
    11  // I assert the expected inertness of this class.
    12  func TestNewAuthenticate(t *testing.T) {
    13  	testSubject := NewAuthenticate(azure.PublicCloud, "clientID", "clientString", "tenantID")
    14  	spn, err := testSubject.getServicePrincipalToken()
    15  	if err != nil {
    16  		t.Fatalf(err.Error())
    17  	}
    18  
    19  	if spn.Token().AccessToken != "" {
    20  		t.Errorf("spn.Token().AccessToken: expected=\"\", actual=%s", spn.Token().AccessToken)
    21  	}
    22  	if spn.Token().RefreshToken != "" {
    23  		t.Errorf("spn.Token().RefreshToken: expected=\"\", actual=%s", spn.Token().RefreshToken)
    24  	}
    25  	if spn.Token().ExpiresIn != "" {
    26  		t.Errorf("spn.Token().ExpiresIn: expected=\"\", actual=%s", spn.Token().ExpiresIn)
    27  	}
    28  	if spn.Token().ExpiresOn != "" {
    29  		t.Errorf("spn.Token().ExpiresOn: expected=\"\", actual=%s", spn.Token().ExpiresOn)
    30  	}
    31  	if spn.Token().NotBefore != "" {
    32  		t.Errorf("spn.Token().NotBefore: expected=\"\", actual=%s", spn.Token().NotBefore)
    33  	}
    34  	if spn.Token().Resource != "" {
    35  		t.Errorf("spn.Token().Resource: expected=\"\", actual=%s", spn.Token().Resource)
    36  	}
    37  	if spn.Token().Type != "" {
    38  		t.Errorf("spn.Token().Type: expected=\"\", actual=%s", spn.Token().Type)
    39  	}
    40  }