# 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:
  # service
  - expected: expected/service.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql browser service ls test-ui
  # version
  - expected: expected/version.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql browser version ls --service-name test-ui
  # page
  - expected: expected/page.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql browser page ls --service-name test-ui
  # browser error log
  - expected: expected/error-log.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql browser logs ls --service-name test-ui --version-name v1.0.0
  # browser service metrics
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_pv --service-id dGVzdC11aQ==.1
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_error_sum --service-id dGVzdC11aQ==.1
  # browser version metrics
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_single_version_pv --service-id dGVzdC11aQ==.1 --instance-name v1.0.0
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_single_version_error_sum --service-id dGVzdC11aQ==.1 --instance-name v1.0.0
  # browser page metrics
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_pv --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_error_sum --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_js_error_sum --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  # browser performance metrics
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_dom_analysis_avg --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_dom_ready_avg --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_load_page_avg --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_ttl_avg --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value-percentile.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_dom_ready_percentile --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  - expected: expected/metrics-has-value-percentile.yml
    query: |
      swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec \
        --expression=browser_app_page_load_page_percentile --service-id dGVzdC11aQ==.1 --endpoint-name index.html
  # dependency service
  - expected: expected/dependency.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency service --service-id dGVzdC11aTxicm93c2VyPg==.1
  # trace
  - expected: expected/traces.yml
    query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls
  - expected: expected/trace-detail.yml
    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 | grep -A 5 'index.html' | tail -n1 | awk -F ' ' '{print $2}')