# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cases:
  # layer list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql layer ls
    expected: expected/layer.yml
  # service list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql service ls
    expected: expected/service.yml
  # service instance list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql instance list --service-name=e2e-service-provider
    expected: expected/service-instance-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql instance list --service-name=e2e-service-consumer
    expected: expected/service-instance-consumer.yml
  # service endpoint
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql endpoint list --keyword=users --service-name=e2e-service-provider
    expected: expected/service-endpoint-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql endpoint list --keyword=users --service-name=e2e-service-consumer
    expected: expected/service-endpoint-consumer.yml
  # dependency service
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency global --layer=GENERAL
    expected: expected/dependency-services-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency service --service-name=e2e-service-provider
    expected: expected/dependency-services-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency service --service-name=e2e-service-consumer
    expected: expected/dependency-services-consumer.yml
  # dependency instance
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency instance --service-name=e2e-service-consumer --dest-service-name=e2e-service-provider
    expected: expected/dependency-instance.yml
  # dependency endpoint
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency endpoint --service-name=e2e-service-provider --endpoint-name=POST:/users
    expected: expected/dependency-endpoint-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency endpoint --service-name=e2e-service-consumer --endpoint-name=POST:/users
    expected: expected/dependency-endpoint-consumer.yml
  # trace segment list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls
    expected: expected/traces-list.yml
  # trace detail
  - query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace $( \
        swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls \
          | yq e '.traces | select(.[].endpointnames[0]=="POST:/users") | .[0].traceids[0]' -
      )
    expected: expected/trace-users-detail.yml
  # service metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_sla --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_cpm --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_resp_time --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_apdex --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_sla --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_cpm --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_resp_time --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_apdex --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service instance metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_resp_time --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_cpm --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_sla --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service instance JVM metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap_max --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_noheap --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_live_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_daemon_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_peak_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_runnable_state_thread_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_loaded_class_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_total_loaded_class_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap_max --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_noheap --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_live_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_daemon_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_peak_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_runnable_state_thread_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_loaded_class_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_total_loaded_class_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  # service endpoint metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_cpm --endpoint-name=POST:/users --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_resp_time --endpoint-name=POST:/users --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_sla --endpoint-name=POST:/users --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_cpm --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_resp_time --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_sla --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service endpoint metrics percentile
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_percentile --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_percentile --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value-percentile.yml
