github.com/replicatedcom/ship@v0.50.0/pkg/specs/replicatedapp/selector_test.go (about)

     1  package replicatedapp
     2  
     3  import (
     4  	"net/url"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestUnmarshalSelector(t *testing.T) {
    11  	tests := []struct {
    12  		name string
    13  		url  string
    14  		want *Selector
    15  	}{
    16  		{
    17  			name: "replicated.app",
    18  			url:  "replicated.app?customer_id=123&installation_id=456&release_id=789&release_semver=7.8.9",
    19  			want: &Selector{
    20  				CustomerID:     "123",
    21  				InstallationID: "456",
    22  				ReleaseID:      "789",
    23  				ReleaseSemver:  "7.8.9",
    24  			},
    25  		},
    26  		{
    27  			name: "staging.replicated.app",
    28  			url:  "staging.replicated.app?customer_id=123&installation_id=456&release_id=789&release_semver=7.8.9",
    29  			want: &Selector{
    30  				CustomerID:     "123",
    31  				InstallationID: "456",
    32  				ReleaseID:      "789",
    33  				ReleaseSemver:  "7.8.9",
    34  				Upstream:       "https://pg.staging.replicated.com/graphql",
    35  			},
    36  		},
    37  		{
    38  			name: "pathed app with customer id",
    39  			url:  "replicated.app/app_id_here?customer_id=123&installation_id=456&release_id=789&release_semver=7.8.9",
    40  			want: &Selector{
    41  				CustomerID:     "123",
    42  				AppSlug:        "",
    43  				InstallationID: "456",
    44  				ReleaseID:      "789",
    45  				ReleaseSemver:  "7.8.9",
    46  			},
    47  		},
    48  		{
    49  			name: "pathed app WITHOUT customer id",
    50  			url:  "replicated.app/app_id_here?installation_id=456&release_id=789&release_semver=7.8.9",
    51  			want: &Selector{
    52  				AppSlug:        "app_id_here",
    53  				InstallationID: "456",
    54  				ReleaseID:      "789",
    55  				ReleaseSemver:  "7.8.9",
    56  			},
    57  		},
    58  		{
    59  			name: "app slug with license id and release number",
    60  			url:  "replicated.app/app/id/here?license_id=456&release_id=789",
    61  			want: &Selector{
    62  				AppSlug:   "app/id/here",
    63  				LicenseID: "456",
    64  				ReleaseID: "789",
    65  			},
    66  		},
    67  		{
    68  			name: "app slug with license id and release number",
    69  			url:  "replicated.app/app/id/here/?license_id=456&release_id=789",
    70  			want: &Selector{
    71  				AppSlug:   "app/id/here",
    72  				LicenseID: "456",
    73  				ReleaseID: "789",
    74  			},
    75  		},
    76  	}
    77  
    78  	for _, test := range tests {
    79  		t.Run(test.name, func(t *testing.T) {
    80  			req := require.New(t)
    81  			parsed, err := url.Parse(test.url)
    82  			req.NoError(err)
    83  			actual := (&Selector{}).UnmarshalFrom(parsed)
    84  			req.Equal(test.want, actual)
    85  		})
    86  	}
    87  }