github.com/jenkins-x/jx/v2@v2.1.155/pkg/jxfactory/connector/provider/integration_test.go (about) 1 // +build integration 2 3 package provider_test 4 5 import ( 6 "io/ioutil" 7 "os" 8 "testing" 9 "time" 10 11 "github.com/jenkins-x/jx/v2/pkg/jxfactory/connector" 12 "github.com/jenkins-x/jx/v2/pkg/jxfactory/connector/provider" 13 "github.com/stretchr/testify/assert" 14 "github.com/stretchr/testify/require" 15 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 16 ) 17 18 // TestGCPConnector tests we can connect to a remote cluster/project/region easily 19 func TestGCPConnector(t *testing.T) { 20 project := os.Getenv("TEST_PROJECT") 21 cluster := os.Getenv("TEST_CLUSTER") 22 region := os.Getenv("TEST_REGION") 23 24 if project == "" || cluster == "" || region == "" { 25 t.SkipNow() 26 return 27 } 28 29 t.Logf("connecting to project %s cluster %s region %s", project, cluster, region) 30 31 workDir, err := ioutil.TempDir("", "jx-test-gcp-connector-") 32 require.NoError(t, err, "failed to generate temp dir") 33 34 t.Logf("using workdir: %s", workDir) 35 36 client := provider.NewClient(workDir) 37 38 conn := &connector.RemoteConnector{GKE: &connector.GKEConnector{ 39 Project: project, 40 Cluster: cluster, 41 Region: region, 42 }} 43 44 config, err := client.Connect(conn) 45 require.NoError(t, err, "failed to connect to %#v", conn.GKE) 46 assert.NotNil(t, config, "no config created") 47 48 factory := connector.NewConfigClientFactory("remote", config) 49 kubeClient, err := factory.CreateKubeClient() 50 require.NoError(t, err, "failed to create KubeClient to %#v", conn.GKE) 51 require.NotNil(t, kubeClient, "no KubeClient created for %#v", conn.GKE) 52 53 list, err := kubeClient.CoreV1().Pods("jx").List(metav1.ListOptions{}) 54 require.NoError(t, err, "Failed to list pods in remote connection namespace jx") 55 56 now := time.Now() 57 58 t.Log("PODS") 59 for _, r := range list.Items { 60 t.Logf("%s %s", r.Name, now.Sub(r.CreationTimestamp.Time).String()) 61 } 62 }