client: remove implicit call to Build on Deploy

This commit is contained in:
Luke Kingland 2021-03-10 19:57:49 +09:00
parent db0945ed3e
commit f115a7a871
No known key found for this signature in database
GPG Key ID: 4896F75BAF2E1966
2 changed files with 37 additions and 3 deletions

View File

@ -33,6 +33,9 @@ type Client struct {
progressListener ProgressListener // progress listener
}
// ErrNotBuilt indicates the Function has not yet been built.
var ErrNotBuilt = errors.New("not built")
// Builder of Function source to runnable image.
type Builder interface {
// Build a Function project with source located at path.
@ -406,9 +409,10 @@ func (c *Client) Deploy(path string) (err error) {
return
}
// Build the Function
if err = c.Build(f.Root); err != nil {
return
// Functions must be built (have an associated image) before being deployed.
// Note that externally built images may be specified in the func.yaml
if !f.Built() {
return ErrNotBuilt
}
// Push the image for the named service to the configured registry

View File

@ -674,6 +674,36 @@ func TestListOutsideRoot(t *testing.T) {
}
}
// TestDeployUnbuilt ensures that a call to deploy a Function which was not
// fully created (ie. was only initialized, not actually built and deploys)
// yields an expected, and informative, error.
func TestDeployUnbuilt(t *testing.T) {
root := "testdata/example.com/testDeploy" // Root from which to run the test
if err := os.MkdirAll(root, 0700); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
// New Client
client := bosonFunc.New(bosonFunc.WithRegistry(TestRegistry))
// Initialize (half-create) a new Function at root
if err := client.Create(bosonFunc.Function{Root: root}); err != nil {
t.Fatal(err)
}
// Now try to deploy it. Ie. without having run the necessary build step.
err := client.Deploy(root)
if err == nil {
t.Fatal("did not receive an error attempting to deploy an unbuilt Function")
}
if !errors.Is(err, bosonFunc.ErrNotBuilt) {
t.Fatalf("did not receive expected error type. Expected ErrNotBuilt, got %T", err)
}
}
// TODO: The tests which confirm an error is generated do not currently test
// that the expected error is received; just that any error is generated.
// This should be replaced with typed errors or at a minimum code prefixes