// Licensed to 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. Apache Software Foundation (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.

package trace

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"github.com/apache/skywalking-banyandb/pkg/meter"
)

// TestStorageScopeNamespace verifies that the new storageScope in this
// package produces the metric-name namespace expected by the dashboard
// and by the sibling stream package.
//
// Expected namespace chain (root separator is "_"):
//
//	banyandb → banyandb_trace → banyandb_trace_tst      (tbScope, unchanged)
//	                            banyandb_trace_storage (storageScope, NEW)
func TestStorageScopeNamespace(t *testing.T) {
	cases := []struct {
		name  string
		scope meter.Scope
		want  string
	}{
		{"traceScope", traceScope, "banyandb_trace"},
		{"tbScope", tbScope, "banyandb_trace_tst"},
		{"storageScope", storageScope, "banyandb_trace_storage"},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			hs, ok := tc.scope.(*meter.HierarchicalScope)
			require.Truef(t, ok, "%s must be a *meter.HierarchicalScope, got %T", tc.name, tc.scope)
			assert.Equal(t, tc.want, hs.GetNamespace())
		})
	}
}
