GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — func/cmd/client_test.go at main · stackbuilders/func

Expand file tree

/

client_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
54 lines (46 loc) · 1.82 KB
/

client_test.go

Copy path

File metadata and controls

54 lines (46 loc) · 1.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cmd
import (
"testing"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/mock"
)
// Test_NewTestClient ensures that the convenience method for
// constructing a mocked client for testing properly considers options:
// options provided to the factory constructor are considered exhaustive,
// such that the test can force the user of the factory to use specific mocks.
// In other words, options provided when invoking the factory (such as by
// a command implementation) are ignored.
func Test_NewTestClient(t *testing.T) {
var (
remover = mock.NewRemover()
describer = mock.NewDescriber()
)
// Factory constructor options which should be used when invoking later
clientFn := NewTestClient(fn.WithRemovers(remover))
// Factory should ignore options provided when invoking
client, _ := clientFn(ClientConfig{}, fn.WithDescribers(describer))
// Trigger an invocation of the mocks by running the associated client
// methods which depend on them
_, err := client.Remove(t.Context(), "myfunc", "myns", fn.Function{}, true)
if err != nil {
t.Fatal(err)
}
_, err = client.Describe(t.Context(), "myfunc", "myns", fn.Function{})
if err != nil {
t.Fatal(err)
}
// Ensure the first set of options, held on the factory (the mock remover)
// is invoked.
if !remover.RemoveInvoked {
t.Fatalf("factory (outer) options not carried through to final client instance")
}
// Ensure the second set of options, provided when constructing the client
// using the factory, are ignored.
if describer.DescribeInvoked {
t.Fatalf("test client factory should ignore options when invoked.")
}
// This ensures that the NewTestClient function, when provided a set
// of optional implementations (mocks) will override any which are set
// by commands, allowing tests to "force" a command to use the mocked
// implementations.
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.