Skip to content

Commit acd913b

Browse files
authored
chore: add support 8.16.2 to go-kibana-rest and acc tests (elastic#964)
1 parent 627fd7b commit acd913b

File tree

11 files changed

+51
-37
lines changed

11 files changed

+51
-37
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124
- '8.13.4'
125125
- '8.14.3'
126126
- '8.15.5'
127+
- '8.16.2'
127128
steps:
128129
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
129130
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
@@ -153,7 +154,7 @@ jobs:
153154

154155
- id: setup-fleet
155156
name: Setup Fleet
156-
if: matrix.version == '8.10.3' || matrix.version == '8.11.4' || matrix.version == '8.12.2' || matrix.version == '8.13.4' || matrix.version == '8.14.3' || matrix.version == '8.15.5'
157+
if: matrix.version == '8.10.3' || matrix.version == '8.11.4' || matrix.version == '8.12.2' || matrix.version == '8.13.4' || matrix.version == '8.14.3' || matrix.version == '8.15.5' || matrix.version == '8.16.2'
157158
run: |-
158159
make setup-kibana-fleet
159160
env:
@@ -162,7 +163,7 @@ jobs:
162163

163164
- id: force-install-synthetics
164165
name: Force install synthetics
165-
if: matrix.version == '8.14.3' || matrix.version == '8.15.5'
166+
if: matrix.version == '8.14.3' || matrix.version == '8.15.5' || matrix.version == '8.16.2'
166167
run: |-
167168
for i in {1..5}; do curl -s -H "Authorization: ApiKey ${{ steps.get-api-key.outputs.apikey }}" --header "Content-Type: application/json" --header "kbn-xsrf: true" --request POST --data '{ "force": true }' http://localhost:5601/api/fleet/epm/packages/synthetics/1.2.2 && break || sleep 15; done
168169

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Acceptance tests
2+
3+
```bash
4+
make docker-testacc
5+
```
6+
7+
Run a single test with terraform debug enabled:
8+
```bash
9+
make docker-testacc TF_LOG=DEBUG TESTARGS='-run ^TestAccResourceDataStreamLifecycle$$'
10+
```

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SWAGGER_VERSION ?= 8.7
1616

1717
GOVERSION ?= $(shell grep -e '^go' go.mod | cut -f 2 -d ' ')
1818

19-
STACK_VERSION ?= 8.15.5
19+
STACK_VERSION ?= 8.16.2
2020

2121
ELASTICSEARCH_NAME ?= terraform-elasticstack-es
2222
ELASTICSEARCH_ENDPOINTS ?= http://$(ELASTICSEARCH_NAME):9200

internal/clients/elasticsearch/index.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,14 @@ func GetDataStreamLifecycle(ctx context.Context, apiClient *clients.ApiClient, d
548548
return nil, utils.FrameworkDiagsFromSDK(diags)
549549
}
550550

551-
dStreams := make(map[string][]models.DataStreamLifecycle)
551+
dStreams := struct {
552+
DataStreams []models.DataStreamLifecycle `json:"data_streams,omitempty"`
553+
}{}
554+
552555
if err := json.NewDecoder(res.Body).Decode(&dStreams); err != nil {
553556
return nil, utils.FrameworkDiagFromError(err)
554557
}
555-
ds := dStreams["data_streams"]
558+
ds := dStreams.DataStreams
556559
return &ds, nil
557560
}
558561

internal/fleet/integration_policy/resource_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func TestAccResourceIntegrationPolicy(t *testing.T) {
7575
func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
7676
policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
7777

78+
sdkConstrains, err := version.NewConstraint(">=8.10.0,<8.16.0")
79+
require.NoError(t, err)
80+
7881
resource.Test(t, resource.TestCase{
7982
PreCheck: func() { acctest.PreCheck(t) },
8083
CheckDestroy: checkResourceIntegrationPolicyDestroy,
@@ -86,7 +89,7 @@ func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
8689
VersionConstraint: "0.11.7",
8790
},
8891
},
89-
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
92+
SkipFunc: versionutils.CheckIfVersionMeetsConstraints(sdkConstrains),
9093
Config: testAccResourceIntegrationPolicySecretsCreate(policyName, "created"),
9194
ExpectNonEmptyPlan: true, // secret churn
9295
Check: resource.ComposeTestCheckFunc(
@@ -103,7 +106,7 @@ func TestAccResourceIntegrationPolicySecretsFromSDK(t *testing.T) {
103106
},
104107
{
105108
ProtoV6ProviderFactories: acctest.Providers,
106-
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionIntegrationPolicy),
109+
SkipFunc: versionutils.CheckIfVersionMeetsConstraints(sdkConstrains),
107110
Config: testAccResourceIntegrationPolicySecretsCreate(policyName, "created"),
108111
Check: resource.ComposeTestCheckFunc(
109112
resource.TestCheckResourceAttr("elasticstack_fleet_integration_policy.test_policy", "name", policyName),

internal/kibana/role.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,11 @@ func resourceRoleUpsert(ctx context.Context, d *schema.ResourceData, meta interf
265265
if err != nil {
266266
return diag.FromErr(err)
267267
}
268-
queryParams := ""
269-
if d.IsNewResource() {
270-
queryParams = "?createOnly=true"
271-
}
272268
kibanaRole := kbapi.KibanaRole{
273-
Name: fmt.Sprintf("%s%s", d.Get("name").(string), queryParams),
269+
Name: d.Get("name").(string),
274270
Kibana: []kbapi.KibanaRoleKibana{},
275271
Elasticsearch: &kbapi.KibanaRoleElasticsearch{},
272+
CreateOnly: d.IsNewResource(),
276273
}
277274

278275
if v, ok := d.GetOk("kibana"); ok {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Unit tests
2+
3+
To run the unit tests, you can use the following command:
4+
```bash
5+
6+
docker compose up -d
7+
make test
8+
```
9+
10+
One could enable debug output for tests by setting environment variable `DEBUG=true`, that helps to see http requests and responses.
11+
12+
Here is an example of environment variables to run a single test, e.g. from IDE or CLI:
13+
```bash
14+
DEBUG=true TEST="-run TestKBAPITestSuite/TestKibanaSpaces ./..." make test
15+
```

libs/go-kibana-rest/docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
elasticsearch:
3-
image: docker.elastic.co/elasticsearch/elasticsearch:8.16.1@sha256:500b04e9282aeffd083fb8f917ee2c309c99f76c095c79681bd77ab37d6886e6
3+
image: docker.elastic.co/elasticsearch/elasticsearch:8.16.2
44
environment:
55
cluster.name: test
66
discovery.type: single-node
@@ -11,7 +11,7 @@ services:
1111
ports:
1212
- "9200:9200/tcp"
1313
set-kibana-password:
14-
image: docker.elastic.co/kibana/kibana:8.16.1@sha256:a22f9f9bb16fc7b01cfd03523a2d5a0d9873daefec6092368a8e2bb0b3380757
14+
image: docker.elastic.co/kibana/kibana:8.16.2
1515
restart: on-failure
1616
links:
1717
- elasticsearch
@@ -22,14 +22,13 @@ services:
2222
elasticsearch:
2323
condition: service_started
2424
kibana:
25-
image: docker.elastic.co/kibana/kibana:8.16.1@sha256:a22f9f9bb16fc7b01cfd03523a2d5a0d9873daefec6092368a8e2bb0b3380757
25+
image: docker.elastic.co/kibana/kibana:8.16.2
2626
environment:
2727
SERVER_NAME: kibana
2828
ELASTICSEARCH_HOSTS: http://es:9200
2929
ELASTICSEARCH_USERNAME: kibana_system
3030
ELASTICSEARCH_PASSWORD: changeme
3131
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: min-32-byte-long-strong-encryption-key
32-
# LOGGING_ROOT_LEVEL: debug
3332
links:
3433
- elasticsearch:es
3534
ports:

libs/go-kibana-rest/kbapi/api.kibana_role_management.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type KibanaRole struct {
1919
TransientMedata *KibanaRoleTransientMetadata `json:"transient_metadata,omitempty"`
2020
Elasticsearch *KibanaRoleElasticsearch `json:"elasticsearch,omitempty"`
2121
Kibana []KibanaRoleKibana `json:"kibana,omitempty"`
22+
CreateOnly bool `json:"-"`
2223
}
2324

2425
// KibanaRoleTransientMetadata is the API TransientMedata object
@@ -153,7 +154,11 @@ func newKibanaRoleManagementCreateOrUpdateFunc(c *resty.Client) KibanaRoleManage
153154
if err != nil {
154155
return nil, err
155156
}
156-
resp, err := c.R().SetBody(jsonData).Put(path)
157+
r := c.R()
158+
if kibanaRole.CreateOnly {
159+
r = r.SetQueryParam("createOnly", "true")
160+
}
161+
resp, err := r.SetBody(jsonData).Put(path)
157162
if err != nil {
158163
return nil, err
159164
}

libs/go-kibana-rest/kbapi/api.kibana_spaces_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s *KBAPITestSuite) TestKibanaSpaces() {
4242
Objects: []KibanaSpaceObjectParameter{
4343
{
4444
Type: "config",
45-
ID: "8.15.0",
45+
ID: "8.16.2",
4646
},
4747
},
4848
}

0 commit comments

Comments
 (0)