-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathopen_test.go
More file actions
116 lines (102 loc) · 3.23 KB
/
open_test.go
File metadata and controls
116 lines (102 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package bundle
import (
"context"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResolveOpenArgument_NoArgs_NonInteractive(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{}
_, err := resolveOpenArgument(ctx, b, nil)
require.Error(t, err)
assert.ErrorContains(t, err, "expected a KEY of the resource to open")
}
func TestResolveOpenArgument_ExactMatch(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"my_job": {JobSettings: jobs.JobSettings{Name: "My Job"}},
"my_job_2": {JobSettings: jobs.JobSettings{Name: "My Job 2"}},
},
},
},
}
key, err := resolveOpenArgument(ctx, b, []string{"my_job"})
require.NoError(t, err)
assert.Equal(t, "my_job", key)
}
func TestResolveOpenArgument_SubstringSingleMatch(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"foo_job": {JobSettings: jobs.JobSettings{Name: "Foo Job"}},
"bar_job": {JobSettings: jobs.JobSettings{Name: "Bar Job"}},
},
},
},
}
key, err := resolveOpenArgument(ctx, b, []string{"foo"})
require.NoError(t, err)
assert.Equal(t, "foo_job", key)
}
func TestResolveOpenArgument_SubstringMultipleMatches_NonInteractive(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"my_job_1": {JobSettings: jobs.JobSettings{Name: "My Job 1"}},
"my_job_2": {JobSettings: jobs.JobSettings{Name: "My Job 2"}},
"other": {JobSettings: jobs.JobSettings{Name: "Other"}},
},
},
},
}
_, err := resolveOpenArgument(ctx, b, []string{"my_"})
require.Error(t, err)
assert.ErrorContains(t, err, "multiple resources match")
assert.ErrorContains(t, err, "my_job_1")
assert.ErrorContains(t, err, "my_job_2")
}
func TestResolveOpenArgument_SubstringMiddleMatch(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"my_foo_job": {JobSettings: jobs.JobSettings{Name: "My Foo Job"}},
"bar_job": {JobSettings: jobs.JobSettings{Name: "Bar Job"}},
},
},
},
}
key, err := resolveOpenArgument(ctx, b, []string{"foo"})
require.NoError(t, err)
assert.Equal(t, "my_foo_job", key)
}
func TestResolveOpenArgument_SubstringNoMatch(t *testing.T) {
ctx := cmdio.MockDiscard(context.Background())
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"foo": {JobSettings: jobs.JobSettings{Name: "Foo"}},
},
},
},
}
// No substring match; returns the arg as-is.
key, err := resolveOpenArgument(ctx, b, []string{"zzz"})
require.NoError(t, err)
assert.Equal(t, "zzz", key)
}