How to use updateSeed method of watch Package

Best Ginkgo code snippet using watch.updateSeed

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

registry.go

Source: registry.go Github

copy
1// Copyright 2018 The Gardener Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package seed
16
17import (
18	"github.com/gardener/gardener/pkg/apis/garden"
19	metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
20	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21	"k8s.io/apimachinery/pkg/watch"
22	genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
23	"k8s.io/apiserver/pkg/registry/rest"
24)
25
26// Registry is an interface for things that know how to store Seeds.
27type Registry interface {
28	ListSeeds(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*garden.SeedList, error)
29	WatchSeeds(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
30	GetSeed(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*garden.Seed, error)
31	CreateSeed(ctx genericapirequest.Context, seed *garden.Seed, createValidation rest.ValidateObjectFunc) (*garden.Seed, error)
32	UpdateSeed(ctx genericapirequest.Context, seed *garden.Seed, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*garden.Seed, error)
33	DeleteSeed(ctx genericapirequest.Context, name string) error
34}
35
36// storage puts strong typing around storage calls
37type storage struct {
38	rest.StandardStorage
39}
40
41// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
42// types will panic.
43func NewRegistry(s rest.StandardStorage) Registry {
44	return &storage{s}
45}
46
47func (s *storage) ListSeeds(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (*garden.SeedList, error) {
48	obj, err := s.List(ctx, options)
49	if err != nil {
50		return nil, err
51	}
52
53	return obj.(*garden.SeedList), err
54}
55
56func (s *storage) WatchSeeds(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) {
57	return s.Watch(ctx, options)
58}
59
60func (s *storage) GetSeed(ctx genericapirequest.Context, name string, options *metav1.GetOptions) (*garden.Seed, error) {
61	obj, err := s.Get(ctx, name, options)
62	if err != nil {
63		return nil, err
64	}
65
66	return obj.(*garden.Seed), nil
67}
68
69func (s *storage) CreateSeed(ctx genericapirequest.Context, seed *garden.Seed, createValidation rest.ValidateObjectFunc) (*garden.Seed, error) {
70	obj, err := s.Create(ctx, seed, createValidation, false)
71	if err != nil {
72		return nil, err
73	}
74
75	return obj.(*garden.Seed), nil
76}
77
78func (s *storage) UpdateSeed(ctx genericapirequest.Context, seed *garden.Seed, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*garden.Seed, error) {
79	obj, _, err := s.Update(ctx, seed.Name, rest.DefaultUpdatedObjectInfo(seed), createValidation, updateValidation)
80	if err != nil {
81		return nil, err
82	}
83
84	return obj.(*garden.Seed), nil
85}
86
87func (s *storage) DeleteSeed(ctx genericapirequest.Context, name string) error {
88	_, _, err := s.Delete(ctx, name, nil)
89	return err
90}
91
Full Screen

watch_command.go

Source: watch_command.go Github

copy
1package watch
2
3import (
4	"fmt"
5	"regexp"
6	"time"
7
8	"github.com/onsi/ginkgo/v2/formatter"
9	"github.com/onsi/ginkgo/v2/ginkgo/command"
10	"github.com/onsi/ginkgo/v2/ginkgo/internal"
11	"github.com/onsi/ginkgo/v2/internal/interrupt_handler"
12	"github.com/onsi/ginkgo/v2/types"
13)
14
15func BuildWatchCommand() command.Command {
16	var suiteConfig = types.NewDefaultSuiteConfig()
17	var reporterConfig = types.NewDefaultReporterConfig()
18	var cliConfig = types.NewDefaultCLIConfig()
19	var goFlagsConfig = types.NewDefaultGoFlagsConfig()
20
21	flags, err := types.BuildWatchCommandFlagSet(&suiteConfig, &reporterConfig, &cliConfig, &goFlagsConfig)
22	if err != nil {
23		panic(err)
24	}
25	interruptHandler := interrupt_handler.NewInterruptHandler(0, nil)
26	interrupt_handler.SwallowSigQuit()
27
28	return command.Command{
29		Name:          "watch",
30		Flags:         flags,
31		Usage:         "ginkgo watch <FLAGS> <PACKAGES> -- <PASS-THROUGHS>",
32		ShortDoc:      "Watch the passed in <PACKAGES> and runs their tests whenever changes occur.",
33		Documentation: "Any arguments after -- will be passed to the test.",
34		DocLink:       "watching-for-changes",
35		Command: func(args []string, additionalArgs []string) {
36			var errors []error
37			cliConfig, goFlagsConfig, errors = types.VetAndInitializeCLIAndGoConfig(cliConfig, goFlagsConfig)
38			command.AbortIfErrors("Ginkgo detected configuration issues:", errors)
39
40			watcher := &SpecWatcher{
41				cliConfig:      cliConfig,
42				goFlagsConfig:  goFlagsConfig,
43				suiteConfig:    suiteConfig,
44				reporterConfig: reporterConfig,
45				flags:          flags,
46
47				interruptHandler: interruptHandler,
48			}
49
50			watcher.WatchSpecs(args, additionalArgs)
51		},
52	}
53}
54
55type SpecWatcher struct {
56	suiteConfig    types.SuiteConfig
57	reporterConfig types.ReporterConfig
58	cliConfig      types.CLIConfig
59	goFlagsConfig  types.GoFlagsConfig
60	flags          types.GinkgoFlagSet
61
62	interruptHandler *interrupt_handler.InterruptHandler
63}
64
65func (w *SpecWatcher) WatchSpecs(args []string, additionalArgs []string) {
66	suites := internal.FindSuites(args, w.cliConfig, false).WithoutState(internal.TestSuiteStateSkippedByFilter)
67
68	if len(suites) == 0 {
69		command.AbortWith("Found no test suites")
70	}
71
72	fmt.Printf("Identified %d test %s.  Locating dependencies to a depth of %d (this may take a while)...\n", len(suites), internal.PluralizedWord("suite", "suites", len(suites)), w.cliConfig.Depth)
73	deltaTracker := NewDeltaTracker(w.cliConfig.Depth, regexp.MustCompile(w.cliConfig.WatchRegExp))
74	delta, errors := deltaTracker.Delta(suites)
75
76	fmt.Printf("Watching %d %s:\n", len(delta.NewSuites), internal.PluralizedWord("suite", "suites", len(delta.NewSuites)))
77	for _, suite := range delta.NewSuites {
78		fmt.Println("  " + suite.Description())
79	}
80
81	for suite, err := range errors {
82		fmt.Printf("Failed to watch %s: %s\n", suite.PackageName, err)
83	}
84
85	if len(suites) == 1 {
86		w.updateSeed()
87		w.compileAndRun(suites[0], additionalArgs)
88	}
89
90	ticker := time.NewTicker(time.Second)
91
92	for {
93		select {
94		case <-ticker.C:
95			suites := internal.FindSuites(args, w.cliConfig, false).WithoutState(internal.TestSuiteStateSkippedByFilter)
96			delta, _ := deltaTracker.Delta(suites)
97			coloredStream := formatter.ColorableStdOut
98
99			suites = internal.TestSuites{}
100
101			if len(delta.NewSuites) > 0 {
102				fmt.Fprintln(coloredStream, formatter.F("{{green}}Detected %d new %s:{{/}}", len(delta.NewSuites), internal.PluralizedWord("suite", "suites", len(delta.NewSuites))))
103				for _, suite := range delta.NewSuites {
104					suites = append(suites, suite.Suite)
105					fmt.Fprintln(coloredStream, formatter.Fi(1, "%s", suite.Description()))
106				}
107			}
108
109			modifiedSuites := delta.ModifiedSuites()
110			if len(modifiedSuites) > 0 {
111				fmt.Fprintln(coloredStream, formatter.F("{{green}}Detected changes in:{{/}}"))
112				for _, pkg := range delta.ModifiedPackages {
113					fmt.Fprintln(coloredStream, formatter.Fi(1, "%s", pkg))
114				}
115				fmt.Fprintln(coloredStream, formatter.F("{{green}}Will run %d %s:{{/}}", len(modifiedSuites), internal.PluralizedWord("suite", "suites", len(modifiedSuites))))
116				for _, suite := range modifiedSuites {
117					suites = append(suites, suite.Suite)
118					fmt.Fprintln(coloredStream, formatter.Fi(1, "%s", suite.Description()))
119				}
120				fmt.Fprintln(coloredStream, "")
121			}
122
123			if len(suites) == 0 {
124				break
125			}
126
127			w.updateSeed()
128			w.computeSuccinctMode(len(suites))
129			for idx := range suites {
130				if w.interruptHandler.Status().Interrupted {
131					return
132				}
133				deltaTracker.WillRun(suites[idx])
134				suites[idx] = w.compileAndRun(suites[idx], additionalArgs)
135			}
136			color := "{{green}}"
137			if suites.CountWithState(internal.TestSuiteStateFailureStates...) > 0 {
138				color = "{{red}}"
139			}
140			fmt.Fprintln(coloredStream, formatter.F(color+"\nDone.  Resuming watch...{{/}}"))
141
142			messages, err := internal.FinalizeProfilesAndReportsForSuites(suites, w.cliConfig, w.suiteConfig, w.reporterConfig, w.goFlagsConfig)
143			command.AbortIfError("could not finalize profiles:", err)
144			for _, message := range messages {
145				fmt.Println(message)
146			}
147		case <-w.interruptHandler.Status().Channel:
148			return
149		}
150	}
151}
152
153func (w *SpecWatcher) compileAndRun(suite internal.TestSuite, additionalArgs []string) internal.TestSuite {
154	suite = internal.CompileSuite(suite, w.goFlagsConfig)
155	if suite.State.Is(internal.TestSuiteStateFailedToCompile) {
156		fmt.Println(suite.CompilationError.Error())
157		return suite
158	}
159	if w.interruptHandler.Status().Interrupted {
160		return suite
161	}
162	suite = internal.RunCompiledSuite(suite, w.suiteConfig, w.reporterConfig, w.cliConfig, w.goFlagsConfig, additionalArgs)
163	internal.Cleanup(w.goFlagsConfig, suite)
164	return suite
165}
166
167func (w *SpecWatcher) computeSuccinctMode(numSuites int) {
168	if w.reporterConfig.Verbosity().GTE(types.VerbosityLevelVerbose) {
169		w.reporterConfig.Succinct = false
170		return
171	}
172
173	if w.flags.WasSet("succinct") {
174		return
175	}
176
177	if numSuites == 1 {
178		w.reporterConfig.Succinct = false
179	}
180
181	if numSuites > 1 {
182		w.reporterConfig.Succinct = true
183	}
184}
185
186func (w *SpecWatcher) updateSeed() {
187	if !w.flags.WasSet("seed") {
188		w.suiteConfig.RandomSeed = time.Now().Unix()
189	}
190}
191
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)