|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "io/ioutil" |
| 6 | + "net/http" |
| 7 | + "os" |
| 8 | + "path/filepath" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | + "time" |
| 12 | + |
| 13 | + "github.com/gruntwork-io/terratest/modules/helm" |
| 14 | + "github.com/gruntwork-io/terratest/modules/k8s" |
| 15 | + "github.com/gruntwork-io/terratest/modules/random" |
| 16 | + digestAuth "github.com/xinsnake/go-http-digest-auth-client" |
| 17 | +) |
| 18 | + |
| 19 | +func TestMarklogicReady(t *testing.T) { |
| 20 | + // Path to the helm chart we will test |
| 21 | + helmChartPath, e := filepath.Abs("../../charts") |
| 22 | + if e != nil { |
| 23 | + t.Fatalf(e.Error()) |
| 24 | + } |
| 25 | + imageRepo, repoPres := os.LookupEnv("dockerRepository") |
| 26 | + imageTag, tagPres := os.LookupEnv("dockerVersion") |
| 27 | + username := "admin" |
| 28 | + password := "admin" |
| 29 | + var resp *http.Response |
| 30 | + var body []byte |
| 31 | + var err error |
| 32 | + |
| 33 | + if !repoPres { |
| 34 | + imageRepo = "marklogic-centos/marklogic-server-centos" |
| 35 | + t.Logf("No imageRepo variable present, setting to default value: " + imageRepo) |
| 36 | + } |
| 37 | + |
| 38 | + if !tagPres { |
| 39 | + imageTag = "10-internal" |
| 40 | + t.Logf("No imageTag variable present, setting to default value: " + imageTag) |
| 41 | + } |
| 42 | + |
| 43 | + namespaceName := "marklogic-" + strings.ToLower(random.UniqueId()) |
| 44 | + kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName) |
| 45 | + options := &helm.Options{ |
| 46 | + KubectlOptions: kubectlOptions, |
| 47 | + SetValues: map[string]string{ |
| 48 | + "persistence.enabled": "false", |
| 49 | + "replicaCount": "2", |
| 50 | + "image.repository": imageRepo, |
| 51 | + "image.tag": imageTag, |
| 52 | + "auth.adminUsername": username, |
| 53 | + "auth.adminPassword": password, |
| 54 | + "logCollection.enabled": "false", |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + t.Logf("====Creating namespace: " + namespaceName) |
| 59 | + k8s.CreateNamespace(t, kubectlOptions, namespaceName) |
| 60 | + |
| 61 | + defer t.Logf("====Deleting namespace: " + namespaceName) |
| 62 | + defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName) |
| 63 | + |
| 64 | + t.Logf("====Installing Helm Chart") |
| 65 | + releaseName := "test-install" |
| 66 | + helm.Install(t, options, helmChartPath, releaseName) |
| 67 | + |
| 68 | + podName := releaseName + "-marklogic-0" |
| 69 | + // wait until the pod is in Ready status |
| 70 | + k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second) |
| 71 | + tunnel := k8s.NewTunnel( |
| 72 | + kubectlOptions, k8s.ResourceTypePod, podName, 8001, 8001) |
| 73 | + defer tunnel.Close() |
| 74 | + tunnel.ForwardPort(t) |
| 75 | + endpoint := fmt.Sprintf("http://%s/admin/v1/timestamp", tunnel.Endpoint()) |
| 76 | + t.Logf(`Endpoint: %s`, endpoint) |
| 77 | + |
| 78 | + // Make request to server as soon as it is ready |
| 79 | + timestamp := digestAuth.NewRequest(username, password, "GET", endpoint, "") |
| 80 | + |
| 81 | + if resp, err = timestamp.Execute(); err != nil { |
| 82 | + t.Fatalf(err.Error()) |
| 83 | + } |
| 84 | + if body, err = ioutil.ReadAll(resp.Body); err != nil { |
| 85 | + t.Fatalf(err.Error()) |
| 86 | + } |
| 87 | + |
| 88 | + t.Logf("Timestamp response:\n" + string(body)) |
| 89 | +} |
0 commit comments