Skip to content

Commit

Permalink
fix integration deploy test, comments
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <fridrich.david19@gmail.com>
  • Loading branch information
gauron99 committed Jan 30, 2024
1 parent 50f2740 commit a1a0840
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cmd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func Test_NewTestClient(t *testing.T) {
var (
remover = mock.NewRemover()
describer = mock.NewDescriber()
namespace = "func"
)

// Factory constructor options which should be used when invoking later
Expand All @@ -27,7 +26,7 @@ func Test_NewTestClient(t *testing.T) {
client, _ := clientFn(ClientConfig{}, fn.WithDescriber(describer))

// Trigger an invocation of the mocks
err := client.Remove(context.Background(), fn.Function{Name: "test", Deploy: fn.DeploySpec{Namespace: namespace}}, true)
err := client.Remove(context.Background(), fn.Function{Name: "test"}, true)
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 4 additions & 8 deletions cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ func TestDelete_Default(t *testing.T) {
// function explicitly as an argument invokes the remover appropriately.
func TestDelete_ByName(t *testing.T) {
var (
root = fromTempDirectory(t)
testname = "testname" // explicit name for the function
namespace = "myns"
remover = mock.NewRemover() // with a mock remover
err error
root = fromTempDirectory(t)
testname = "testname" // explicit name for the function
remover = mock.NewRemover() // with a mock remover
err error
)

// Remover fails the test if it receives the incorrect name
Expand All @@ -81,9 +80,6 @@ func TestDelete_ByName(t *testing.T) {
Runtime: "go",
Registry: TestRegistry,
Name: "testname",
Deploy: fn.DeploySpec{
Namespace: namespace, //simulate deployed Function in this namespace
},
}

if f, err = fn.New().Init(f); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
// should be deployed as is
if digested {
f.Deploy.Image = cfg.Image
// TODO: remove this -- edit subsequent tests
f.Build.Image = cfg.Image // when digested image is used and not remotely built, set .Build.Image

} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/functions/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ func (c *Client) List(ctx context.Context) ([]ListItem, error) {
// Remove a function. Name takes precedence. If no name is provided, the
// function defined at root is used if it exists. If calling this directly
// namespace must be provided in .Deploy.Namespace field except when using mocks
// in which case empty namespace is accepted because its existance is checked
// in which case empty namespace is accepted because its existence is checked
// in the sub functions remover.Remove and pipilines.Remove
func (c *Client) Remove(ctx context.Context, cfg Function, deleteAll bool) error {
// If name is provided, it takes precedence.
Expand Down
17 changes: 14 additions & 3 deletions pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,29 @@ func TestNew(t *testing.T) {
}
}

// TestDeploy updates
// TestDeploy deployes using client methods from New but manually
func TestDeploy(t *testing.T) {
defer Within(t, "testdata/example.com/deploy")()
verbose := true

client := newClient(verbose)
f := fn.Function{Name: "deploy", Root: ".", Runtime: "go"}
var err error
if _, f, err = client.New(context.Background(), f); err != nil {

if f, err = client.Init(f); err != nil {
t.Fatal(err)
}
if f, err = client.Build(context.Background(), f); err != nil {
t.Fatal(err)
}
if f, err = client.Push(context.Background(), f); err != nil {
t.Fatal(err)
}

defer del(t, client, "deploy")
// TODO: gauron99 -- remove this when you set full image name after build instead
// of push -- this has to be here because of a workaround
f.Deploy.Image = f.Build.Image

if f, err = client.Deploy(context.Background(), f); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -575,7 +586,7 @@ func newClient(verbose bool) *fn.Client {
func del(t *testing.T, c *fn.Client, name string) {
t.Helper()
waitFor(t, c, name)
if err := c.Remove(context.Background(), fn.Function{Name: name, Deploy: fn.DeploySpec{Namespace: DefaultNamespace}}, false); err != nil {
if err := c.Remove(context.Background(), fn.Function{Name: name}, false); err != nil {
t.Fatal(err)
}
cli, _, err := docker.NewClient(client.DefaultDockerHost)
Expand Down
8 changes: 4 additions & 4 deletions pkg/knative/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
const LIVENESS_ENDPOINT = "/health/liveness"
const READINESS_ENDPOINT = "/health/readiness"

// static default namespace
const DefaultNamespace = "func"
// static default namespace for deployer
const StaticDefaultNamespace = "func"

type DeployDecorator interface {
UpdateAnnotations(fn.Function, map[string]string) map[string]string
Expand Down Expand Up @@ -146,15 +146,15 @@ func namespace(dflt string, f fn.Function) string {
namespace, err = k8s.GetDefaultNamespace()
if err != nil {
fmt.Fprintf(os.Stderr, "trying to get default namespace returns an error: %s\n", err)
namespace = DefaultNamespace
namespace = StaticDefaultNamespace
}
}
return namespace
}

func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (fn.DeploymentResult, error) {

// returns correct namespace combining
// returns correct namespace by priority
namespace := namespace(d.Namespace, f)

client, err := NewServingClient(namespace)
Expand Down

0 comments on commit a1a0840

Please sign in to comment.