mirror of https://github.com/databricks/cli.git
Add unit test for `command.ConfigUsed` (#2446)
## Changes I forgot to add a unit test in the original PR, so adding it here: https://github.com/databricks/cli/pull/2440 ## Why Unit testing code is a good practice. I believe we all should unit test code. ## Tests N/A NO_CHANGELOG=true
This commit is contained in:
parent
1a02422d56
commit
5948339f92
|
@ -0,0 +1,37 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/databricks/databricks-sdk-go/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCommandConfigUsed(t *testing.T) {
|
||||
cfg := &config.Config{
|
||||
Host: "https://test.com",
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
// Panic if ConfigUsed is called before SetConfigUsed.
|
||||
assert.Panics(t, func() {
|
||||
ConfigUsed(ctx)
|
||||
})
|
||||
|
||||
ctx = SetConfigUsed(ctx, cfg)
|
||||
|
||||
// Multiple calls should return a pointer to the same config.
|
||||
c := ConfigUsed(ctx)
|
||||
assert.Same(t, c, ConfigUsed(ctx))
|
||||
|
||||
// The config should have the correct configuration.
|
||||
assert.Equal(t, "https://test.com", ConfigUsed(ctx).Host)
|
||||
|
||||
// Second call should update the config used.
|
||||
cfg2 := &config.Config{
|
||||
Host: "https://test2.com",
|
||||
}
|
||||
ctx = SetConfigUsed(ctx, cfg2)
|
||||
assert.Equal(t, "https://test2.com", ConfigUsed(ctx).Host)
|
||||
}
|
Loading…
Reference in New Issue