Skip to content

Commit

Permalink
new test, comment
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <[email protected]>
  • Loading branch information
gauron99 committed Dec 12, 2023
1 parent 44cc15f commit 9653c75
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
64 changes: 64 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ory/viper"
"github.com/spf13/cobra"

apiErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/func/pkg/builders"
"knative.dev/func/pkg/config"
fn "knative.dev/func/pkg/functions"
Expand Down Expand Up @@ -1611,3 +1613,65 @@ func TestReDeploy_ErrorOnRegistryChangeWithoutBuild(t *testing.T) {
t.Fatalf("expected error message '%v' but got '%v'", expectedError, err.Error())
}
}

// TestWarnDuringOldFuncUndeploy assures that warning is printed out when old Function's
// service is not available (is already deleted manualy or the namespace doesnt exist etc.)

Check failure on line 1618 in cmd/deploy_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[github.com/client9/misspell] reported by reviewdog 🐶 "manualy" is a misspelling of "manually" Raw Output: cmd/deploy_test.go:1618:48: "manualy" is a misspelling of "manually"
// Warning: Cant undeploy Function in namespace
func TestWarnDuringOldFuncUndeploy(t *testing.T) {
var (
root = fromTempDirectory(t)
nsOne = "nsone"
nsTwo = "nstwo"
remover = mock.NewRemover()
)

// Create a basic go Function
f := fn.Function{
Runtime: "go",
Root: root,
}
_, err := fn.New().Init(f)
if err != nil {
t.Fatal(err)
}

// Deploy the function to ns "nsone"
cmd := NewDeployCmd(NewTestClient(
fn.WithDeployer(mock.NewDeployer()),
fn.WithRegistry(TestRegistry),
fn.WithRemover(remover)))

cmd.SetArgs([]string{fmt.Sprintf("--namespace=%s", nsOne)})
err = cmd.Execute()
if err != nil {
t.Fatal(err)
}

// Simulate remover error
remover.RemoveFn = func(n string) error {
return apiErrors.NewNotFound(schema.GroupResource{Group: "", Resource: "Namespace"}, nsOne)
}

// Second Deploy with different namespace
cmd.SetArgs([]string{fmt.Sprintf("--namespace=%s", nsTwo)})

stdout := strings.Builder{}
cmd.SetOut(&stdout)
err = cmd.Execute()

expectedWarning := fmt.Sprintf("Warning: Cant undeploy Function in namespace '%s' - service not found. Namespace/Service might be deleted already", nsOne)

// ASSERT

// Needs to pass since the error is set to nil with the warning message below
// that is printed out
if err != nil {
t.Fatal(err)
}

// Ensure output contained warning message
if !strings.Contains(stdout.String(), expectedWarning) {
t.Log("STDOUT:\n" + stdout.String())
t.Fatalf("Expected warning not found:\n%v", expectedWarning)
}
}
4 changes: 2 additions & 2 deletions pkg/functions/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ func TestClient_Update(t *testing.T) {
}

// TestClient_Deploy_RegistryUpdate ensures that deploying a Function updates
// its image member on initial deploy, and on subsequent deploys only
// if reset to it zero value.
// its image member on initial deploy, and on subsequent deploys where f.Image
// takes precedence
func TestClient_Deploy_RegistryUpdate(t *testing.T) {
root, rm := Mktemp(t)
defer rm()
Expand Down

0 comments on commit 9653c75

Please sign in to comment.