Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <[email protected]>
  • Loading branch information
gauron99 committed Feb 19, 2024
1 parent 3d288fc commit 483bd36
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
59 changes: 42 additions & 17 deletions cmd/delete_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"os"
"testing"

Expand Down Expand Up @@ -108,15 +109,13 @@ func TestDelete_ByName(t *testing.T) {
}
}

// TestDelete_Namespace ensures that the deployed Function is deleted correctly
// with namespace option
// TestDelete_Namespace ensures that remover is envoked when --namespace flag is
// given --> func delete myfunc --namespace myns
func TestDelete_Namespace(t *testing.T) {
var (
root = fromTempDirectory(t)
namespace = "myns"
remover = mock.NewRemover()
testname = "testname"
err error
)

remover.RemoveFn = func(_, ns string) error {
Expand All @@ -126,27 +125,53 @@ func TestDelete_Namespace(t *testing.T) {
return nil
}

// Ensure the extant function's namespace is used
f := fn.Function{
Name: testname,
Root: root,
Runtime: "go",
Registry: TestRegistry,
Deploy: fn.DeploySpec{
Namespace: namespace,
},
cmd := NewDeleteCmd(NewTestClient(fn.WithRemover(remover)))
cmd.SetArgs([]string{testname, "--namespace", namespace})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}

if f, err = fn.New().Init(f); err != nil {
t.Fatal(err)
if !remover.RemoveInvoked {
t.Fatal("remover was not invoked")
}
}

if err = f.Write(); err != nil {
// TestDelete_NamespaceFlagPriority ensures that even thought there is
// a deployed function the namespace flag takes precedence and essentially
// ignores the the function on disk
func TestDelete_NamespaceFlagPriority(t *testing.T) {
var (
root = fromTempDirectory(t)
namespace = "myns"
namespace2 = "myns2"
remover = mock.NewRemover()
testname = "testname"
err error
)

remover.RemoveFn = func(_, ns string) error {
if ns != namespace2 {
t.Fatalf("expected delete namespace '%v', got '%v'", namespace2, ns)
}
return nil
}

// Ensure the extant function's namespace is used
f := fn.Function{
Name: testname,
Root: root,
Runtime: "go",
Registry: TestRegistry,
Namespace: namespace,
}
client := fn.New()
_, _, err = client.New(context.Background(), f)
if err != nil {
t.Fatal(err)
}

cmd := NewDeleteCmd(NewTestClient(fn.WithRemover(remover)))
cmd.SetArgs([]string{testname, "--namespace", namespace})
cmd.SetArgs([]string{testname, "--namespace", namespace2})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,13 @@ func TestDeploy_ImageWithDigestErrors(t *testing.T) {
}
}

// TestDeploy_ImageWithDigestDoesntPopulateBuild ensures that when --image is
// given with digest f.Build.Image is not populated because no image building
// should happen; f.Deploy.Image should be populated because the image should
// just be deployed as is (since it already has digest)
func TestDeploy_ImageWithDigestDoesntPopulateBuild(t *testing.T) {
root := fromTempDirectory(t)
// image with digest (well almost, atleast in length and syntax)
const img = "docker.io/4141gauron3268@sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
// Create a new Function in the temp directory
_, err := fn.New().Init(fn.Function{Runtime: "go", Root: root})
Expand Down
8 changes: 4 additions & 4 deletions pkg/functions/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ func TestClient_Deploy_RegistryUpdate(t *testing.T) {
}
}

// TestClient_Deploy_NamespaceUpdate ensures that namespace deploymen has
// TestClient_Deploy_NamespaceUpdate ensures that namespace deployment has
// the correct priorities, that means:
// 'default' gets overridden by 'already deployed' if aplicable and all gets
// overridden by 'specifically desired namespace'.
Expand Down Expand Up @@ -2051,12 +2051,12 @@ func TestClient_BuildCleanFingerprint(t *testing.T) {
}
}

// Test_RemoveInvokedOnOldFunction checks that Remover was invoked after a
// subsequent redeploy to a new namespace.
// TestClient_DeployRemoves ensures that the Remover is invoked when a
// function is moved to a new namespace.
// specifically: deploy to 'nsone' -> simulate change of namespace with change to
// f.Namespace -> redeploy to that namespace and expect the remover to be invoked
// for old Function in ns 'nsone'.
func TestClient_RemoveInvokedOnOldFunction(t *testing.T) {
func TestClient_DeployRemoves(t *testing.T) {
// Create a temporary directory
root, cleanup := Mktemp(t)
defer cleanup()
Expand Down

0 comments on commit 483bd36

Please sign in to comment.