Skip to content

Commit 2cc0396

Browse files
committed
fix: test and namespace isolation
1 parent 7e95ca2 commit 2cc0396

17 files changed

+199
-180
lines changed

cmd/build_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
fn "knative.dev/func/pkg/functions"
88
"knative.dev/func/pkg/mock"
9+
. "knative.dev/func/pkg/testing"
910
)
1011

1112
// TestBuild_BuilderPersists ensures that the builder chosen is read from
@@ -94,7 +95,7 @@ func TestBuild_RegistryOrImageRequired(t *testing.T) {
9495
// - Push not triggered after an unsuccessful build
9596
// - Push can be disabled
9697
func TestBuild_Push(t *testing.T) {
97-
root := fromTempDirectory(t)
98+
root := FromTempDirectory(t)
9899

99100
f := fn.Function{
100101
Root: root,

cmd/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewClient(cfg ClientConfig, options ...fn.Option) (*fn.Client, func()) {
6262
var (
6363
t = newTransport(cfg.InsecureSkipVerify) // may provide a custom impl which proxies
6464
c = newCredentialsProvider(config.Dir(), t) // for accessing registries
65-
d = newKnativeDeployer(cfg.Namespace, cfg.Verbose)
65+
d = newKnativeDeployer(cfg.Verbose)
6666
pp = newTektonPipelinesProvider(cfg.Namespace, c, cfg.Verbose)
6767
o = []fn.Option{ // standard (shared) options for all commands
6868
fn.WithVerbose(cfg.Verbose),
@@ -128,9 +128,8 @@ func newTektonPipelinesProvider(namespace string, creds docker.CredentialsProvid
128128
return tekton.NewPipelinesProvider(options...)
129129
}
130130

131-
func newKnativeDeployer(namespace string, verbose bool) fn.Deployer {
131+
func newKnativeDeployer(verbose bool) fn.Deployer {
132132
options := []knative.DeployerOpt{
133-
knative.WithDeployerNamespace(namespace),
134133
knative.WithDeployerVerbose(verbose),
135134
knative.WithDeployerDecorator(deployDecorator{}),
136135
}

cmd/create_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"errors"
55
"testing"
66

7+
. "knative.dev/func/pkg/testing"
78
"knative.dev/func/pkg/utils"
89
)
910

1011
// TestCreate_Execute ensures that an invocation of create with minimal settings
1112
// and valid input completes without error; degenerate case.
1213
func TestCreate_Execute(t *testing.T) {
13-
_ = fromTempDirectory(t)
14+
_ = FromTempDirectory(t)
1415

1516
cmd := NewCreateCmd(NewClient)
1617
cmd.SetArgs([]string{"--language", "go", "myfunc"})
@@ -23,7 +24,7 @@ func TestCreate_Execute(t *testing.T) {
2324
// TestCreate_NoRuntime ensures that an invocation of create must be
2425
// done with a runtime.
2526
func TestCreate_NoRuntime(t *testing.T) {
26-
_ = fromTempDirectory(t)
27+
_ = FromTempDirectory(t)
2728

2829
cmd := NewCreateCmd(NewClient)
2930
cmd.SetArgs([]string{"myfunc"}) // Do not use test command args
@@ -38,7 +39,7 @@ func TestCreate_NoRuntime(t *testing.T) {
3839
// TestCreate_WithNoRuntime ensures that an invocation of create must be
3940
// done with one of the valid runtimes only.
4041
func TestCreate_WithInvalidRuntime(t *testing.T) {
41-
_ = fromTempDirectory(t)
42+
_ = FromTempDirectory(t)
4243

4344
cmd := NewCreateCmd(NewClient)
4445
cmd.SetArgs([]string{"--language", "invalid", "myfunc"})
@@ -53,7 +54,7 @@ func TestCreate_WithInvalidRuntime(t *testing.T) {
5354
// TestCreate_InvalidTemplate ensures that an invocation of create must be
5455
// done with one of the valid templates only.
5556
func TestCreate_InvalidTemplate(t *testing.T) {
56-
_ = fromTempDirectory(t)
57+
_ = FromTempDirectory(t)
5758

5859
cmd := NewCreateCmd(NewClient)
5960
cmd.SetArgs([]string{"--language", "go", "--template", "invalid", "myfunc"})
@@ -68,7 +69,7 @@ func TestCreate_InvalidTemplate(t *testing.T) {
6869
// TestCreate_ValidatesName ensures that the create command only accepts
6970
// DNS-1123 labels for function name.
7071
func TestCreate_ValidatesName(t *testing.T) {
71-
_ = fromTempDirectory(t)
72+
_ = FromTempDirectory(t)
7273

7374
// Execute the command with a function name containing invalid characters and
7475
// confirm the expected error is returned
@@ -84,7 +85,7 @@ func TestCreate_ValidatesName(t *testing.T) {
8485
// TestCreate_ConfigOptional ensures that the system can be used without
8586
// any additional configuration being required.
8687
func TestCreate_ConfigOptional(t *testing.T) {
87-
_ = fromTempDirectory(t)
88+
_ = FromTempDirectory(t)
8889

8990
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
9091

cmd/delete_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77

88
fn "knative.dev/func/pkg/functions"
99
"knative.dev/func/pkg/mock"
10+
. "knative.dev/func/pkg/testing"
1011
)
1112

1213
// TestDelete_Default ensures that the deployed function is deleted correctly
1314
// with default options
1415
func TestDelete_Default(t *testing.T) {
1516
var (
16-
root = fromTempDirectory(t)
17+
root = FromTempDirectory(t)
1718
namespace = "myns"
1819
remover = mock.NewRemover()
1920
err error
@@ -61,7 +62,7 @@ func TestDelete_Default(t *testing.T) {
6162
// function explicitly as an argument invokes the remover appropriately.
6263
func TestDelete_ByName(t *testing.T) {
6364
var (
64-
root = fromTempDirectory(t)
65+
root = FromTempDirectory(t)
6566
testname = "testname" // explicit name for the function
6667
testnamespace = "testnamespace" // explicit namespace for the function
6768
remover = mock.NewRemover() // with a mock remover
@@ -141,7 +142,7 @@ func TestDelete_Namespace(t *testing.T) {
141142
// ignores the the function on disk
142143
func TestDelete_NamespaceFlagPriority(t *testing.T) {
143144
var (
144-
root = fromTempDirectory(t)
145+
root = FromTempDirectory(t)
145146
namespace = "myns"
146147
namespace2 = "myns2"
147148
remover = mock.NewRemover()
@@ -184,7 +185,7 @@ func TestDelete_NamespaceFlagPriority(t *testing.T) {
184185
// TestDelete_NamespaceWithoutNameFails ensures that providing wrong argument
185186
// combination fails nice and fast (no name of the Function)
186187
func TestDelete_NamespaceWithoutNameFails(t *testing.T) {
187-
_ = fromTempDirectory(t)
188+
_ = FromTempDirectory(t)
188189

189190
cmd := NewDeleteCmd(NewTestClient())
190191
cmd.SetArgs([]string{"--namespace=myns"})
@@ -196,7 +197,7 @@ func TestDelete_NamespaceWithoutNameFails(t *testing.T) {
196197
// TestDelete_ByProject ensures that running delete with a valid project as its
197198
// context invokes remove and with the correct name (reads name from func.yaml)
198199
func TestDelete_ByProject(t *testing.T) {
199-
_ = fromTempDirectory(t)
200+
_ = FromTempDirectory(t)
200201

201202
// Write a func.yaml config which specifies a name
202203
funcYaml := `name: bar
@@ -248,7 +249,7 @@ func TestDelete_ByPath(t *testing.T) {
248249

249250
// A mock remover which will be sampled to ensure it is not invoked.
250251
remover = mock.NewRemover()
251-
root = fromTempDirectory(t)
252+
root = FromTempDirectory(t)
252253
err error
253254
namespace = "func"
254255
)

0 commit comments

Comments
 (0)