github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/proxy_test.go (about)

     1  package plural_test
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  
     9  	"github.com/pluralsh/plural-operator/apis/platform/v1alpha1"
    10  	"github.com/stretchr/testify/mock"
    11  
    12  	"github.com/pluralsh/plural-cli/cmd/plural"
    13  	"github.com/pluralsh/plural-cli/pkg/test/mocks"
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestProxyList(t *testing.T) {
    18  	tests := []struct {
    19  		name             string
    20  		args             []string
    21  		proxyList        *v1alpha1.ProxyList
    22  		expectedResponse string
    23  	}{
    24  		{
    25  			name: `test "proxy list"`,
    26  			args: []string{plural.ApplicationName, "proxy", "list", "test"},
    27  			proxyList: &v1alpha1.ProxyList{
    28  				TypeMeta: metav1.TypeMeta{},
    29  				Items: []v1alpha1.Proxy{
    30  					{
    31  						ObjectMeta: metav1.ObjectMeta{Name: "proxy-1"},
    32  						Spec:       v1alpha1.ProxySpec{Type: v1alpha1.Sh, Target: "test-1"},
    33  					},
    34  					{
    35  						ObjectMeta: metav1.ObjectMeta{Name: "proxy-1"},
    36  						Spec:       v1alpha1.ProxySpec{Type: v1alpha1.Web, Target: "test-2"},
    37  					},
    38  				},
    39  			},
    40  			expectedResponse: `+---------+------+--------+
    41  |  NAME   | TYPE | TARGET |
    42  +---------+------+--------+
    43  | proxy-1 | sh   | test-1 |
    44  | proxy-1 | web  | test-2 |
    45  +---------+------+--------+
    46  `,
    47  		},
    48  	}
    49  	for _, test := range tests {
    50  		t.Run(test.name, func(t *testing.T) {
    51  			client := mocks.NewClient(t)
    52  			kube := mocks.NewKube(t)
    53  			kube.On("ProxyList", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(test.proxyList, nil)
    54  			app := plural.CreateNewApp(&plural.Plural{Client: client, Kube: kube})
    55  			app.HelpName = plural.ApplicationName
    56  			os.Args = test.args
    57  			res, err := captureStdout(app, os.Args)
    58  			assert.NoError(t, err)
    59  
    60  			assert.Equal(t, test.expectedResponse, res)
    61  		})
    62  	}
    63  }