github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/registry/response/terraform_provider_test.go (about)

     1  package response
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  var (
     9  	testGPGKeyOne = &GPGKey{
    10  		ASCIIArmor: "---\none\n---",
    11  	}
    12  	testGPGKeyTwo = &GPGKey{
    13  		ASCIIArmor: "---\ntwo\n---",
    14  	}
    15  )
    16  
    17  func TestSigningKeyList_GPGASCIIArmor(t *testing.T) {
    18  	var tests = []struct {
    19  		name     string
    20  		gpgKeys  []*GPGKey
    21  		expected string
    22  	}{
    23  		{
    24  			name:     "no keys",
    25  			gpgKeys:  []*GPGKey{},
    26  			expected: "",
    27  		},
    28  		{
    29  			name:     "one key",
    30  			gpgKeys:  []*GPGKey{testGPGKeyOne},
    31  			expected: testGPGKeyOne.ASCIIArmor,
    32  		},
    33  		{
    34  			name:    "two keys",
    35  			gpgKeys: []*GPGKey{testGPGKeyOne, testGPGKeyTwo},
    36  			expected: fmt.Sprintf("%s\n%s",
    37  				testGPGKeyOne.ASCIIArmor, testGPGKeyTwo.ASCIIArmor),
    38  		},
    39  	}
    40  	for _, tt := range tests {
    41  		t.Run(tt.name, func(t *testing.T) {
    42  			signingKeys := &SigningKeyList{
    43  				GPGKeys: tt.gpgKeys,
    44  			}
    45  			actual := signingKeys.GPGASCIIArmor()
    46  
    47  			if actual != tt.expected {
    48  				t.Errorf("expected %s, got %s", tt.expected, actual)
    49  			}
    50  		})
    51  	}
    52  }