9
9
package security_test
10
10
11
11
import (
12
+ "github.com/opensearch-project/opensearch-go/v4"
12
13
"testing"
13
14
14
15
"github.com/stretchr/testify/assert"
@@ -32,7 +33,7 @@ func TestAccountClient(t *testing.T) {
32
33
33
34
type accountTests struct {
34
35
Name string
35
- Results func () (ossectest .Response , error )
36
+ Results func () (any , * opensearch .Response , error )
36
37
}
37
38
38
39
testCases := []struct {
@@ -44,13 +45,13 @@ func TestAccountClient(t *testing.T) {
44
45
Tests : []accountTests {
45
46
{
46
47
Name : "without request" ,
47
- Results : func () (ossectest .Response , error ) {
48
+ Results : func () (any , * opensearch .Response , error ) {
48
49
return client .Account .Get (nil , nil )
49
50
},
50
51
},
51
52
{
52
53
Name : "inspect" ,
53
- Results : func () (ossectest .Response , error ) {
54
+ Results : func () (any , * opensearch .Response , error ) {
54
55
return failingClient .Account .Get (nil , nil )
55
56
},
56
57
},
@@ -61,20 +62,19 @@ func TestAccountClient(t *testing.T) {
61
62
Tests : []accountTests {
62
63
{
63
64
Name : "with request" ,
64
- Results : func () (ossectest.Response , error ) {
65
- var nilResp ossectest.Response
65
+ Results : func () (any , * opensearch.Response , error ) {
66
66
// Get new client config
67
67
config , err := ossectest .ClientConfig ()
68
68
if err != nil {
69
- return nilResp , err
69
+ return nil , nil , err
70
70
}
71
71
72
72
// Set password to a "strong" password
73
73
config .Client .Password = "Str0ngP4ss123!"
74
74
config .Client .Username = testUser
75
75
76
76
// Create the test user
77
- _ , err = client .InternalUsers .Put (
77
+ _ , _ , err = client .InternalUsers .Put (
78
78
nil ,
79
79
security.InternalUsersPutReq {
80
80
User : config .Client .Username ,
@@ -84,13 +84,13 @@ func TestAccountClient(t *testing.T) {
84
84
},
85
85
)
86
86
if err != nil {
87
- return nilResp , err
87
+ return nil , nil , err
88
88
}
89
89
90
90
// Create a new client with the test user
91
91
usrClient , err := security .NewClient (* config )
92
92
if err != nil {
93
- return nilResp , err
93
+ return nil , nil , err
94
94
}
95
95
96
96
// Run the change password request we want to test
@@ -107,7 +107,7 @@ func TestAccountClient(t *testing.T) {
107
107
},
108
108
{
109
109
Name : "inspect" ,
110
- Results : func () (ossectest .Response , error ) {
110
+ Results : func () (any , * opensearch .Response , error ) {
111
111
return failingClient .Account .Put (nil , security.AccountPutReq {})
112
112
},
113
113
},
@@ -118,16 +118,16 @@ func TestAccountClient(t *testing.T) {
118
118
t .Run (value .Name , func (t * testing.T ) {
119
119
for _ , testCase := range value .Tests {
120
120
t .Run (testCase .Name , func (t * testing.T ) {
121
- res , err := testCase .Results ()
121
+ res , httpResp , err := testCase .Results ()
122
122
if testCase .Name == "inspect" {
123
123
assert .NotNil (t , err )
124
124
assert .NotNil (t , res )
125
- ossectest .VerifyInspect (t , res . Inspect () )
125
+ ossectest .VerifyResponse (t , httpResp )
126
126
} else {
127
127
require .Nil (t , err )
128
128
require .NotNil (t , res )
129
- assert .NotNil (t , res . Inspect (). Response )
130
- ostest .CompareRawJSONwithParsedJSON (t , res , res . Inspect (). Response )
129
+ assert .NotNil (t , httpResp )
130
+ ostest .CompareRawJSONwithParsedJSON (t , res , httpResp )
131
131
}
132
132
})
133
133
}
0 commit comments