Skip to content

Commit 93c5033

Browse files
authored
OAS-10586 Remove go-driver tests jq dependency for agency dump (#655)
* Replaced jq with a go script * zutano check * Makefile fix * Git cleanup
1 parent d185cdb commit 93c5033

File tree

4 files changed

+81
-23
lines changed

4 files changed

+81
-23
lines changed

Makefile

-14
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@ endif
8080

8181
TEST_NET := --net=host
8282

83-
SPACE :=
84-
TABV4 := $(SPACE) $(SPACE) $(SPACE) $(SPACE)
85-
ifdef DUMP_AGENCY_ON_FAILURE
86-
$(info Checking for jq...)
87-
CHECK_JQ_INSTALLTION := $(shell jq --version 2>&1 >/dev/null | cat)
88-
ifneq ($(CHECK_JQ_INSTALLTION),)
89-
$(info )
90-
$(info Error: 'jq' is not installed. This check happens because DUMP_AGENCY_ON_FAILURE is set, and 'jq' is used during the creation of the agency dump. Verified for version jq==1.6. )
91-
$(info Try installing it with:)
92-
$(info $(TABV4) sudo apt install jq)
93-
$(info )
94-
$(error $(CHECK_JQ_INSTALLTION))
95-
endif
96-
endif
9783
# Installation of jq is required for processing AGENCY_DUMP
9884
# ifdef DUMP_AGENCY_ON_FAILURE
9985
# CHECK_JQ_INSTALLTION := $(shell command -v jq >/dev/null 2>&1 || (

collection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2017-2021 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2017-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -183,7 +183,7 @@ type CollectionProperties struct {
183183

184184
IsSmartChild bool `json:"isSmartChild,omitempty"`
185185

186-
InternalValidatorType *int `json:"internalValidatorType, omitempty"`
186+
InternalValidatorType *int `json:"internalValidatorType,omitempty"`
187187

188188
// Set to create a smart edge or vertex collection.
189189
// This requires ArangoDB Enterprise Edition.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package main
22+
23+
import (
24+
"encoding/json"
25+
"fmt"
26+
"io"
27+
"os"
28+
)
29+
30+
func ExtractValue(input io.Reader) error {
31+
var data map[string]interface{}
32+
33+
decoder := json.NewDecoder(input)
34+
if err := decoder.Decode(&data); err != nil {
35+
return fmt.Errorf("failed to decode JSON: %w", err)
36+
}
37+
38+
configuration, ok := data["configuration"].(map[string]interface{})
39+
if !ok {
40+
return fmt.Errorf("key 'configuration' not found or not an object")
41+
}
42+
pool, ok := configuration["pool"].(map[string]interface{})
43+
if !ok {
44+
return fmt.Errorf("key 'pool' not found or not an array")
45+
}
46+
47+
leaderId, ok := data["leaderId"].(string)
48+
if !ok {
49+
return fmt.Errorf("key 'leaderId' not found or not a str")
50+
}
51+
if leaderId == "" {
52+
return fmt.Errorf("key 'leaderId' not set")
53+
}
54+
55+
endpoint, ok := pool[leaderId].(string)
56+
if !ok {
57+
return fmt.Errorf("key '%s' not found or not a str", leaderId)
58+
}
59+
fmt.Println(endpoint)
60+
61+
return nil
62+
}
63+
64+
func main() {
65+
if err := ExtractValue(os.Stdin); err != nil {
66+
fmt.Fprintf(os.Stderr, "JsonAgencyConfigParseError: %v\n and as a result the agency dump could not be created.\n", err)
67+
68+
}
69+
}

test/on_failure.sh

+10-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ if [ -n "${DUMP_AGENCY_ON_FAILURE}" ] && [ "${TEST_MODE}" = "cluster" ]; then
3030
# _api/agency/config returns leader endpoint with protocol that is usually not supported by curl
3131
AGENCY_CONFIG=$(bash -c "curl -k --no-progress-meter ${AUTH} ${ANY_ENDPOINT}/_api/agency/config")
3232

33-
LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | jq -r '.configuration.pool[.leaderId]' | cat)
33+
# same as: jq -r '.configuration.pool[.leaderId]'
34+
LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL=$(echo $AGENCY_CONFIG | go run ./test/json_agency_config_parse_leader_id/json_agency_config_parse_leader_id.go | cat)
3435
SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT="s/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//${PROTOCOL}:\/\//"
3536
LEADER_ENDPOINT=$(echo $LEADER_ENDPOINT_WITH_UNSUPPORTED_PROTOCOL | sed $SED_UNSUPPORTED_PROTOCOL_ENDPOINT_TO_ENDPOINT)
36-
echo "Leader agent endpoint: $LEADER_ENDPOINT"
3737

38-
DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE
39-
mkdir -p $(dirname ${DUMP_FILE_PATH})
40-
AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state")
41-
echo $AGENCY_DUMP > $DUMP_FILE_PATH
42-
echo "Agency dump created at $(realpath $DUMP_FILE_PATH)"
38+
if expr "$LEADER_ENDPOINT" : "^$PROTOCOL" > /dev/null; then
39+
echo "Leader agent endpoint: $LEADER_ENDPOINT"
40+
DUMP_FILE_PATH=$DUMP_AGENCY_ON_FAILURE
41+
mkdir -p $(dirname ${DUMP_FILE_PATH})
42+
AGENCY_DUMP=$(bash -c "curl -Lk --no-progress-meter ${AUTH} ${LEADER_ENDPOINT}/_api/agency/state")
43+
echo $AGENCY_DUMP > $DUMP_FILE_PATH
44+
echo "Agency dump created at $(realpath $DUMP_FILE_PATH)"
45+
fi
4346
fi
4447

4548
echo "\nV${MAJOR_VERSION} Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}";

0 commit comments

Comments
 (0)