databricks-cli/bundle/run/runner_test.go

85 lines
1.5 KiB
Go
Raw Permalink Normal View History

2022-12-15 14:12:47 +00:00
package run
import (
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
2022-12-15 14:12:47 +00:00
"github.com/stretchr/testify/assert"
)
func TestFindNoResources(t *testing.T) {
2022-12-15 14:12:47 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{},
},
}
_, err := Find(b, "foo")
2022-12-15 14:12:47 +00:00
assert.ErrorContains(t, err, "bundle defines no resources")
}
func TestFindSingleArg(t *testing.T) {
2022-12-15 14:12:47 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"foo": {},
},
},
},
}
_, err := Find(b, "foo")
2022-12-15 14:12:47 +00:00
assert.NoError(t, err)
}
func TestFindSingleArgNotFound(t *testing.T) {
2022-12-15 14:12:47 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"foo": {},
},
},
},
}
_, err := Find(b, "bar")
2022-12-15 14:12:47 +00:00
assert.ErrorContains(t, err, "no such resource: bar")
}
func TestFindSingleArgAmbiguous(t *testing.T) {
2022-12-15 14:12:47 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"key": {},
},
Pipelines: map[string]*resources.Pipeline{
"key": {},
},
},
},
}
_, err := Find(b, "key")
2022-12-15 14:12:47 +00:00
assert.ErrorContains(t, err, "ambiguous: ")
}
func TestFindSingleArgWithType(t *testing.T) {
2022-12-15 14:12:47 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"key": {},
},
},
},
}
_, err := Find(b, "jobs.key")
2022-12-15 14:12:47 +00:00
assert.NoError(t, err)
}