How to use initSpecsCache method of infoGatherer Package

Best Gauge code snippet using infoGatherer.initSpecsCache

specDetails_test.go

Source:specDetails_test.go Github

copy

Full Screen

...161	_, err := createFileIn(s.specsDir, "spec1.spec", spec1)162	c.Assert(err, Equals, nil)163	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}164	specInfoGatherer.waitGroup.Add(1)165	specInfoGatherer.initSpecsCache()166	c.Assert(len(specInfoGatherer.specsCache.specDetails), Equals, 1)167}168func (s *MySuite) TestInitConceptsCache(c *C) {169	_, err := createFileIn(s.specsDir, "concept1.cpt", concept1)170	c.Assert(err, Equals, nil)171	_, err = createFileIn(s.specsDir, "concept2.cpt", concept2)172	c.Assert(err, Equals, nil)173	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.projectDir + string(filepath.Separator) + specDir}}174	specInfoGatherer.waitGroup.Add(1)175	specInfoGatherer.initConceptsCache()176	c.Assert(len(specInfoGatherer.conceptsCache.concepts), Equals, 2)177}178func (s *MySuite) TestInitStepsCache(c *C) {179	f, _ := createFileIn(s.specsDir, "spec1.spec", spec1)180	f, _ = filepath.Abs(f)181	f1, _ := createFileIn(s.specsDir, "concept2.cpt", concept2)182	f1, _ = filepath.Abs(f1)183	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}184	specInfoGatherer.waitGroup.Add(3)185	specInfoGatherer.initConceptsCache()186	specInfoGatherer.initSpecsCache()187	specInfoGatherer.initStepsCache()188	c.Assert(len(specInfoGatherer.stepsCache.steps[f]), Equals, 2)189	c.Assert(len(specInfoGatherer.stepsCache.steps[f1]), Equals, 3)190}191func (s *MySuite) TestInitTagsCache(c *C) {192	f, _ := createFileIn(s.specsDir, "specWithTags.spec", specWithTags)193	f, _ = filepath.Abs(f)194	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}195	specInfoGatherer.waitGroup.Add(2)196	specInfoGatherer.initSpecsCache()197	specInfoGatherer.initTagsCache()198	c.Assert(len(specInfoGatherer.Tags()), Equals, 5)199}200func (s *MySuite) TestInitTagsCacheWithMultipleFiles(c *C) {201	f, _ := createFileIn(s.specsDir, "specWithTags.spec", specWithTags)202	f, _ = filepath.Abs(f)203	f1, _ := createFileIn(s.specsDir, "spec2WithTags.spec", spec2WithTags)204	f1, _ = filepath.Abs(f1)205	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}206	specInfoGatherer.waitGroup.Add(2)207	specInfoGatherer.initSpecsCache()208	specInfoGatherer.initTagsCache()209	c.Assert(len(specInfoGatherer.Tags()), Equals, 6)210}211func (s *MySuite) TestGetStepsFromCachedSpecs(c *C) {212	var stepsFromSpecsMap = make(map[string][]*gauge.Step, 0)213	f, _ := createFileIn(s.specsDir, "spec1.spec", spec1)214	f, _ = filepath.Abs(f)215	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}216	specInfoGatherer.waitGroup.Add(3)217	specInfoGatherer.initSpecsCache()218	stepsFromSpecsMap = specInfoGatherer.getStepsFromCachedSpecs()219	c.Assert(len(stepsFromSpecsMap[f]), Equals, 2)220	c.Assert(stepsFromSpecsMap[f][0].Value, Equals, "say hello")221	c.Assert(stepsFromSpecsMap[f][1].Value, Equals, "say {} to me")222}223func (s *MySuite) TestGetStepsFromCachedConcepts(c *C) {224	var stepsFromConceptsMap = make(map[string][]*gauge.Step, 0)225	f, _ := createFileIn(s.specsDir, "concept1.cpt", concept1)226	f, _ = filepath.Abs(f)227	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}228	specInfoGatherer.waitGroup.Add(3)229	specInfoGatherer.initSpecsCache()230	specInfoGatherer.initConceptsCache()231	stepsFromConceptsMap = specInfoGatherer.getStepsFromCachedConcepts()232	c.Assert(len(stepsFromConceptsMap[f]), Equals, 3)233	c.Assert(stepsFromConceptsMap[f][0].Value, Equals, "first step with {}")234	c.Assert(stepsFromConceptsMap[f][1].Value, Equals, "say {} to me")235	c.Assert(stepsFromConceptsMap[f][2].Value, Equals, "a {} step")236}237func (s *MySuite) TestGetAvailableSteps(c *C) {238	var steps []*gauge.Step239	createFileIn(s.specsDir, "spec1.spec", spec1)240	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}241	specInfoGatherer.waitGroup.Add(2)242	specInfoGatherer.initSpecsCache()243	specInfoGatherer.initStepsCache()244	steps = specInfoGatherer.Steps(true)245	c.Assert(len(steps), Equals, 2)246	if !hasStep(steps, "say hello") {247		c.Fatalf("Step value not found %s", "say hello")248	}249	if !hasStep(steps, "say {} to me") {250		c.Fatalf("Step value not found %s", "say {} to me")251	}252}253func (s *MySuite) TestGetAvailableStepsShouldFilterDuplicates(c *C) {254	var steps []*gauge.Step255	createFileIn(s.specsDir, "spec2.spec", spec2)256	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}257	specInfoGatherer.waitGroup.Add(2)258	specInfoGatherer.initSpecsCache()259	specInfoGatherer.initStepsCache()260	steps = specInfoGatherer.Steps(true)261	c.Assert(len(steps), Equals, 2)262	if !hasStep(steps, "say hello") {263		c.Fatalf("Step value not found %s", "say hello")264	}265	if !hasStep(steps, "say {} to me") {266		c.Fatalf("Step value not found %s", "say {} to me")267	}268}269func (s *MySuite) TestGetAvailableStepsShouldFilterConcepts(c *C) {270	var steps []*gauge.Step271	createFileIn(s.specsDir, "concept1.cpt", concept4)272	createFileIn(s.specsDir, "spec1.spec", specWithConcept)273	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}274	specInfoGatherer.waitGroup.Add(3)275	specInfoGatherer.initConceptsCache()276	specInfoGatherer.initSpecsCache()277	specInfoGatherer.initStepsCache()278	steps = specInfoGatherer.Steps(true)279	c.Assert(len(steps), Equals, 1)280	if hasStep(steps, "foo bar with 1 step") {281		c.Fatalf("Step value found %s", "foo bar with 1 step")282	}283	steps = specInfoGatherer.Steps(false)284	c.Assert(len(steps), Equals, 2)285	if !hasStep(steps, "foo bar with 1 step") {286		c.Fatalf("Step value not found %s", "foo bar with 1 step")287	}288}289func (s *MySuite) TestGetAvailableAllStepsShouldFilterConcepts(c *C) {290	var steps []*gauge.Step291	createFileIn(s.specsDir, "concept1.cpt", concept4)292	createFileIn(s.specsDir, "spec1.spec", specWithConcept)293	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}294	specInfoGatherer.waitGroup.Add(3)295	specInfoGatherer.initConceptsCache()296	specInfoGatherer.initSpecsCache()297	specInfoGatherer.initStepsCache()298	steps = specInfoGatherer.AllSteps(true)299	c.Assert(len(steps), Equals, 2)300	if hasStep(steps, "foo bar with 1 step") {301		c.Fatalf("Step value found %s", "foo bar with 1 step")302	}303	steps = specInfoGatherer.AllSteps(false)304	c.Assert(len(steps), Equals, 3)305	if !hasStep(steps, "foo bar with 1 step") {306		c.Fatalf("Step value not found %s", "foo bar with 1 step")307	}308}309func hasStep(steps []*gauge.Step, stepText string) bool {310	for _, step := range steps {311		if step.Value == stepText {312			return true313		}314	}315	return false316}317func (s *MySuite) TestHasSpecForSpecDetail(c *C) {318	c.Assert((&SpecDetail{}).HasSpec(), Equals, false)319	c.Assert((&SpecDetail{Spec: &gauge.Specification{}}).HasSpec(), Equals, false)320	c.Assert((&SpecDetail{Spec: &gauge.Specification{Heading: &gauge.Heading{}}}).HasSpec(), Equals, true)321}322func (s *MySuite) TestGetAvailableSpecDetails(c *C) {323	_, err := createFileIn(s.specsDir, "spec1.spec", spec1)324	c.Assert(err, Equals, nil)325	sig := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}, specsCache: specsCache{specDetails: make(map[string]*SpecDetail)}}326	specFiles := util.FindSpecFilesIn(s.specsDir)327	sig.specsCache.specDetails[specFiles[0]] = &SpecDetail{Spec: &gauge.Specification{Heading: &gauge.Heading{Value: "Specification Heading"}}}328	details := sig.GetAvailableSpecDetails(specFiles)329	c.Assert(len(details), Equals, 1)330	c.Assert(details[0].Spec.Heading.Value, Equals, "Specification Heading")331}332func (s *MySuite) TestGetAvailableSpecDetailsInDefaultDir(c *C) {333	_, err := createFileIn(s.specsDir, "spec1.spec", spec1)334	c.Assert(err, Equals, nil)335	wd, _ := os.Getwd()336	os.Chdir(s.projectDir)337	defer os.Chdir(wd)338	sig := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}, specsCache: specsCache{specDetails: make(map[string]*SpecDetail)}}339	specFiles := util.FindSpecFilesIn(specDir)340	sig.specsCache.specDetails[specFiles[0]] = &SpecDetail{Spec: &gauge.Specification{Heading: &gauge.Heading{Value: "Specification Heading"}}}341	details := sig.GetAvailableSpecDetails([]string{})342	c.Assert(len(details), Equals, 1)343	c.Assert(details[0].Spec.Heading.Value, Equals, "Specification Heading")344}345func (s *MySuite) TestGetAvailableSpecDetailsWithEmptyCache(c *C) {346	_, err := createFileIn(s.specsDir, "spec1.spec", spec1)347	c.Assert(err, Equals, nil)348	sig := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}349	details := sig.GetAvailableSpecDetails([]string{})350	c.Assert(len(details), Equals, 0)351}352func (s *MySuite) TestParamsForStepFile(c *C) {353	file, _ := createFileIn(s.specsDir, "spec3.spec", spec3)354	file, _ = filepath.Abs(file)355	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}356	specInfoGatherer.waitGroup.Add(2)357	specInfoGatherer.initConceptsCache()358	specInfoGatherer.initSpecsCache()359	specInfoGatherer.initStepsCache()360	specInfoGatherer.initParamsCache()361	staticParams := specInfoGatherer.Params(file, gauge.Static)362	c.Assert(len(staticParams), Equals, 1)363	dynamicParams := specInfoGatherer.Params(file, gauge.Dynamic)364	c.Assert(len(dynamicParams), Equals, 3)365	hasParam := func(param string, list []gauge.StepArg) bool {366		for _, p := range list {367			if p.ArgValue() == param {368				return true369			}370		}371		return false372	}373	if !hasParam("hello", staticParams) {374		c.Errorf(`Param "hello" not found`)375	}376	if !hasParam("bye", dynamicParams) {377		c.Errorf(`Param "bye" not found`)378	}379	if !hasParam("Col1", dynamicParams) {380		c.Errorf(`Param "Col1" not found`)381	}382	if !hasParam("Col2", dynamicParams) {383		c.Errorf(`Param "Col1" not found`)384	}385}386func (s *MySuite) TestParamsForConceptFile(c *C) {387	file, _ := createFileIn(s.specsDir, "concept3.cpt", concept3)388	file, _ = filepath.Abs(file)389	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}390	specInfoGatherer.waitGroup.Add(2)391	specInfoGatherer.initConceptsCache()392	specInfoGatherer.initSpecsCache()393	specInfoGatherer.initStepsCache()394	specInfoGatherer.initParamsCache()395	staticParams := specInfoGatherer.Params(file, gauge.Static)396	c.Assert(len(staticParams), Equals, 1)397	dynamicParams := specInfoGatherer.Params(file, gauge.Dynamic)398	c.Assert(len(dynamicParams), Equals, 2)399	hasParam := func(param string, list []gauge.StepArg) bool {400		for _, p := range list {401			if p.ArgValue() == param {402				return true403			}404		}405		return false406	}407	if !hasParam("foo", staticParams) {408		c.Errorf(`Param "foo" not found`)409	}410	if !hasParam("param", dynamicParams) {411		c.Errorf(`Param "param" not found`)412	}413	if !hasParam("final", dynamicParams) {414		c.Errorf(`Param "final" not found`)415	}416}417func (s *MySuite) TestAllStepsOnFileRename(c *C) {418	file, _ := createFileIn(s.specsDir, "spec1.spec", spec1)419	file, _ = filepath.Abs(file)420	specInfoGatherer := &SpecInfoGatherer{SpecDirs: []string{s.specsDir}}421	specInfoGatherer.initSpecsCache()422	specInfoGatherer.initStepsCache()423	c.Assert(len(specInfoGatherer.AllSteps(true)), Equals, 2)424	renameFileIn(s.specsDir, "spec1.spec", "spec42.spec")425	c.Assert(len(specInfoGatherer.AllSteps(true)), Equals, 2)426}427func createFileIn(dir string, fileName string, data []byte) (string, error) {428	os.MkdirAll(dir, 0755)429	err := ioutil.WriteFile(filepath.Join(dir, fileName), data, 0644)430	return filepath.Join(dir, fileName), err431}432func renameFileIn(dir string, oldFileName string, newFileName string) (string, error) {433	err := os.Rename(filepath.Join(dir, oldFileName), filepath.Join(dir, newFileName))434	return filepath.Join(dir, newFileName), err435}...

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	diskRecorder, err := diskrecorder.NewDiskRecorder("/home/rohan/go/src/github.com/openshift/insights-operator/cmd/insights-operator")4	if err != nil {5		panic(err)6	}7	recorder := recorder.New(diskRecorder)8	gatherer := gatherers.NewGatherer(recorder)9	infoGatherer := statusreporter.NewInfoGatherer(gatherer)10	config := &statusreporter.ControllerConfig{11	}12	recorder = recorder.New(diskRecorder)13	gatherer = gatherers.NewGatherer(recorder)14	infoGatherer = statusreporter.NewInfoGatherer(gatherer)15	controller := statusreporter.NewController(config, infoGatherer)

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2type InfoGatherer struct {3	Channel chan interface{}4}5func NewInfoGatherer(c config.Config) *InfoGatherer {6	clientset, err := utils.NewClient()7	if err != nil {8		log.Logger.Fatal("Error creating Kubernetes client")9	}10	filterEngine := filterengine.NewFilterEngine(c.Settings.Filters, c.Settings.Exclude)11	executor := execute.NewExecutor(c.Settings.Executor, c.Settings.Kubectl)12	return &InfoGatherer{13		Channel:       make(chan interface{}, 100),14	}15}16func (i *InfoGatherer) initSpecsCache() {17	go func() {18		for {19			log.Logger.Debug("Fetching specs")20			specs, err := i.Executor.GetClusterSpecs()21			if err != nil {22				log.Logger.Error("Error getting specs")23			}24			i.Executor.UpdateSpecsCache(specs)

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println("Hello, playground")4	gatherer := infoGatherer.NewInfoGatherer()5	gatherer.InitSpecsCache()6}

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	infoGathererObj := infoGatherer.InfoGatherer{}4	err := infoGathererObj.InitSpecsCache()5	if err != nil {6		fmt.Println(err)7	}8	fmt.Println(infoGathererObj.SpecsCache)9}

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2var (3	fileLogger = GetFileLogger()4func main() {5	vpcFileProvider, err := vpcfile.NewFileProvider("vpcfile")6	if err != nil {7		fileLogger.Error("Failed to create new VPC File Provider...", zap.Reflect("NewFileProviderError", err))8	}9	ctxLogger := fileLogger.With(zap.Reflect("TraceID", utils.GenerateTrace()))10	ctx := context.WithValue(context.Background(), ContextLogger, ctxLogger)11	vpcFileService, err := vpcFileProvider.NewFileService(&provider.FileServiceConfig{12		Authenticator: &utils.Authenticator{},13	})14	if err != nil {15		fileLogger.Error("Failed to create new VPC File Service...", zap.Reflect("NewFileServiceError", err))16	}17	vpcFileInfo, err := vpcFileService.NewFileInfo(&provider.FileInfoConfig{18		Volume: &models.Volume{19		},20	})21	if err != nil {22		fileLogger.Error("Failed to create new VPC File Info...", zap.Reflect("NewFileInfoError", err))23	}24	err = vpcFileInfo.InitSpecsCache(ctx)25	if err != nil {26		fileLogger.Error("Failed to initialize specs cache...", zap.Reflect("InitSpecsCacheError", err))27	}28	specsCache := vpcFileInfo.GetSpecsCache()29	if specsCache == nil {30		fileLogger.Error("Failed to get specs cache...")31	}

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	flag.Parse()4	clientConfig, err := clientcmd.DefaultClientConfig(flags).ClientConfig()5	if err != nil {6		glog.Fatalf("Error getting client: %v", err)7	}8	osClient, err := client.New(clientConfig)9	if err != nil {10		glog.Fatalf("Error getting client: %v", err)11	}

Full Screen

Full Screen

initSpecsCache

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println("Hello, playground")4	infoGatherer = NewInfoGatherer(client)5	infoGatherer.initSpecsCache()6	fmt.Println("cache", reflect.TypeOf(infoGatherer.cache))7	fmt.Println("cache", reflect.TypeOf(infoGatherer.cache["pods"]))8	var pods api.PodList = infoGatherer.cache["pods"].([]api.Pod)9	fmt.Println("pods", reflect.TypeOf(pods))10	fmt.Println("pods", pods)11}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful