-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensearch_secure_integration_test.go
70 lines (60 loc) · 1.85 KB
/
opensearch_secure_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.
// +build integration,secure
package opensearch_test
import (
"crypto/tls"
"encoding/json"
"log"
"net/http"
"testing"
"github.com/opensearch-project/opensearch-go/v2"
"github.com/stretchr/testify/assert"
)
func getSecuredClient() (*opensearch.Client, error) {
return opensearch.NewClient(opensearch.Config{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Addresses: []string{"https://localhost:9200"},
Username: "admin",
Password: "admin",
})
}
type clusterVersion struct {
Number string `json:"number"`
BuildFlavor string `json:"build_flavor"`
Distribution string `json:"distribution"`
}
type Info struct {
Version clusterVersion `json:"version"`
Tagline string `json:"tagline"`
}
func TestSecuredClientAPI(t *testing.T) {
t.Run("Check Info", func(t *testing.T) {
client, err := getSecuredClient()
if err != nil {
log.Fatalf("Error creating the client: %s\n", err)
}
res, err := client.Info()
if err != nil {
log.Fatalf("Error getting the response: %s\n", err)
}
defer res.Body.Close()
var infoResponse Info
err = json.NewDecoder(res.Body).Decode(&infoResponse)
if err != nil {
log.Fatalf("Error parsing the response: %s\n", err)
}
assert.True(t, len(infoResponse.Version.Number) > 0, "version number should not be empty")
assert.True(t, len(infoResponse.Tagline) > 0, "tagline should not be empty")
assert.True(t, len(infoResponse.Version.Distribution) > 0 || len(infoResponse.Version.BuildFlavor) > 0,
"Either distribution or build flavor should not be empty")
})
}