2023-02-03 15:47:33 +00:00
|
|
|
package root
|
|
|
|
|
|
|
|
import (
|
2024-11-01 14:08:09 +00:00
|
|
|
"context"
|
2023-02-03 15:47:33 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-11-01 14:08:09 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/useragent"
|
2023-02-03 15:47:33 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2024-11-01 14:08:09 +00:00
|
|
|
func TestWithCommandInUserAgent(t *testing.T) {
|
2023-02-03 15:47:33 +00:00
|
|
|
root := &cobra.Command{
|
|
|
|
Use: "root",
|
|
|
|
}
|
|
|
|
|
|
|
|
hello := &cobra.Command{
|
|
|
|
Use: "hello",
|
|
|
|
}
|
|
|
|
|
|
|
|
world := &cobra.Command{
|
|
|
|
Use: "world",
|
|
|
|
}
|
|
|
|
|
|
|
|
root.AddCommand(hello)
|
|
|
|
hello.AddCommand(world)
|
|
|
|
|
|
|
|
assert.Equal(t, "root", commandString(root))
|
|
|
|
assert.Equal(t, "hello", commandString(hello))
|
|
|
|
assert.Equal(t, "hello_world", commandString(world))
|
2024-11-01 14:08:09 +00:00
|
|
|
|
|
|
|
ctx := withCommandInUserAgent(context.Background(), world)
|
|
|
|
|
|
|
|
ua := useragent.FromContext(ctx)
|
|
|
|
assert.Contains(t, ua, "cmd/hello_world")
|
2023-02-03 15:47:33 +00:00
|
|
|
}
|