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

     1  package regsrc
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestNewTerraformProviderNamespace(t *testing.T) {
     8  	tests := []struct {
     9  		name              string
    10  		provider          string
    11  		expectedNamespace string
    12  		expectedName      string
    13  	}{
    14  		{
    15  			name:              "default",
    16  			provider:          "null",
    17  			expectedNamespace: "-",
    18  			expectedName:      "null",
    19  		}, {
    20  			name:              "explicit",
    21  			provider:          "terraform-providers/null",
    22  			expectedNamespace: "terraform-providers",
    23  			expectedName:      "null",
    24  		}, {
    25  			name:              "community",
    26  			provider:          "community-providers/null",
    27  			expectedNamespace: "community-providers",
    28  			expectedName:      "null",
    29  		},
    30  	}
    31  
    32  	for _, tt := range tests {
    33  		t.Run(tt.name, func(t *testing.T) {
    34  			actual := NewTerraformProvider(tt.provider, "", "")
    35  
    36  			if actual == nil {
    37  				t.Fatal("NewTerraformProvider() unexpectedly returned nil provider")
    38  			}
    39  
    40  			if v := actual.RawNamespace; v != tt.expectedNamespace {
    41  				t.Fatalf("RawNamespace = %v, wanted %v", v, tt.expectedNamespace)
    42  			}
    43  			if v := actual.RawName; v != tt.expectedName {
    44  				t.Fatalf("RawName = %v, wanted %v", v, tt.expectedName)
    45  			}
    46  		})
    47  	}
    48  }