github.com/databricks/cli@v0.203.0/bundle/run/runner_test.go (about)

     1  package run
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/databricks/cli/bundle"
     7  	"github.com/databricks/cli/bundle/config"
     8  	"github.com/databricks/cli/bundle/config/resources"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestFindNoResources(t *testing.T) {
    13  	b := &bundle.Bundle{
    14  		Config: config.Root{
    15  			Resources: config.Resources{},
    16  		},
    17  	}
    18  
    19  	_, err := Find(b, "foo")
    20  	assert.ErrorContains(t, err, "bundle defines no resources")
    21  }
    22  
    23  func TestFindSingleArg(t *testing.T) {
    24  	b := &bundle.Bundle{
    25  		Config: config.Root{
    26  			Resources: config.Resources{
    27  				Jobs: map[string]*resources.Job{
    28  					"foo": {},
    29  				},
    30  			},
    31  		},
    32  	}
    33  
    34  	_, err := Find(b, "foo")
    35  	assert.NoError(t, err)
    36  }
    37  
    38  func TestFindSingleArgNotFound(t *testing.T) {
    39  	b := &bundle.Bundle{
    40  		Config: config.Root{
    41  			Resources: config.Resources{
    42  				Jobs: map[string]*resources.Job{
    43  					"foo": {},
    44  				},
    45  			},
    46  		},
    47  	}
    48  
    49  	_, err := Find(b, "bar")
    50  	assert.ErrorContains(t, err, "no such resource: bar")
    51  }
    52  
    53  func TestFindSingleArgAmbiguous(t *testing.T) {
    54  	b := &bundle.Bundle{
    55  		Config: config.Root{
    56  			Resources: config.Resources{
    57  				Jobs: map[string]*resources.Job{
    58  					"key": {},
    59  				},
    60  				Pipelines: map[string]*resources.Pipeline{
    61  					"key": {},
    62  				},
    63  			},
    64  		},
    65  	}
    66  
    67  	_, err := Find(b, "key")
    68  	assert.ErrorContains(t, err, "ambiguous: ")
    69  }
    70  
    71  func TestFindSingleArgWithType(t *testing.T) {
    72  	b := &bundle.Bundle{
    73  		Config: config.Root{
    74  			Resources: config.Resources{
    75  				Jobs: map[string]*resources.Job{
    76  					"key": {},
    77  				},
    78  			},
    79  		},
    80  	}
    81  
    82  	_, err := Find(b, "jobs.key")
    83  	assert.NoError(t, err)
    84  }