...

Source file src/github.com/redhat-developer/odo/pkg/kclient/kclient_test.go

Documentation: github.com/redhat-developer/odo/pkg/kclient

     1  package kclient
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"testing"
     7  
     8  	"k8s.io/apimachinery/pkg/version"
     9  	"k8s.io/client-go/discovery/fake"
    10  )
    11  
    12  func (c *fakeDiscovery) ServerVersion() (*version.Info, error) {
    13  	return &c.versionInfo, nil
    14  }
    15  
    16  type fakeDiscovery struct {
    17  	*fake.FakeDiscovery
    18  	versionInfo version.Info
    19  }
    20  
    21  func TestClient_IsSSASupported(t *testing.T) {
    22  
    23  	tests := []struct {
    24  		name    string
    25  		version version.Info
    26  		want    bool
    27  	}{
    28  		{
    29  			name: "k8s with SSA",
    30  			version: version.Info{
    31  				Major:        "1",
    32  				Minor:        "16",
    33  				GitVersion:   "1.16.0+000000",
    34  				GitCommit:    "",
    35  				GitTreeState: "",
    36  				BuildDate:    "",
    37  				GoVersion:    runtime.Version(),
    38  				Compiler:     runtime.Compiler,
    39  				Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
    40  			},
    41  			want: true,
    42  		},
    43  		{
    44  			name: "k8s without SSA",
    45  			version: version.Info{
    46  				Major:        "1",
    47  				Minor:        "15",
    48  				GitVersion:   "1.15.0+000000",
    49  				GitCommit:    "",
    50  				GitTreeState: "",
    51  				BuildDate:    "",
    52  				GoVersion:    runtime.Version(),
    53  				Compiler:     runtime.Compiler,
    54  				Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
    55  			},
    56  			want: false,
    57  		},
    58  		{
    59  			name: "invalid k8s version",
    60  			version: version.Info{
    61  				Major:        "a",
    62  				Minor:        "b",
    63  				GitVersion:   "c",
    64  				GitCommit:    "",
    65  				GitTreeState: "",
    66  				BuildDate:    "",
    67  				GoVersion:    runtime.Version(),
    68  				Compiler:     runtime.Compiler,
    69  				Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
    70  			}, want: true,
    71  		},
    72  	}
    73  	for _, tt := range tests {
    74  		fkclient, _ := FakeNew()
    75  		fd := fakeDiscovery{}
    76  		fd.versionInfo = tt.version
    77  		fkclient.SetDiscoveryInterface(&fd)
    78  
    79  		t.Run(tt.name, func(t *testing.T) {
    80  			if got := fkclient.IsSSASupported(); got != tt.want {
    81  				t.Errorf("IsSSASupported() = %v, want %v", got, tt.want)
    82  			}
    83  		})
    84  	}
    85  }
    86  

View as plain text