MCPcopy Index your code
hub / github.com/devspace-sh/devspace / TestParseCommands

Function TestParseCommands

pkg/devspace/config/loader/loader_test.go:481–534  ·  view source on GitHub ↗

TODO: Finish this test!

(t *testing.T)

Source from the content-addressed store, hash-verified

479
480// TODO: Finish this test!
481func TestParseCommands(t *testing.T) {
482 testCases := []parseCommandsTestCase{
483 {
484 data: map[string]interface{}{
485 "version": latest.Version,
486 },
487 },
488 }
489
490 for idx, testCase := range testCases {
491 t.Run("Test "+strconv.Itoa(idx), func(t *testing.T) {
492 f, err := os.CreateTemp("", "")
493 if err != nil {
494 t.Fatal(err)
495 }
496
497 defer os.Remove(f.Name())
498
499 out, err := yaml.Marshal(testCase.data)
500 if err != nil {
501 t.Fatal(err)
502 }
503
504 _, err = f.Write(out)
505 if err != nil {
506 t.Fatal(err)
507 }
508
509 // Close before reading
510 f.Close()
511 loader := &configLoader{
512 absConfigPath: f.Name(),
513 }
514
515 commandsInterface, err := loader.LoadWithParser(context.Background(),
516 localcache.New(constants.DefaultConfigPath),
517 &fakekubectl.Client{Client: fake.NewSimpleClientset()},
518 NewCommandsParser(),
519 nil, log.Discard)
520 if testCase.expectedErr == "" {
521 assert.NilError(t, err, "Error in testCase %s", testCase.name)
522 } else {
523 assert.Error(t, err, testCase.expectedErr, "Wrong or no error in testCase %s", testCase.name)
524 }
525 commands := commandsInterface.Config().Commands
526
527 commandsAsYaml, err := yaml.Marshal(commands)
528 assert.NilError(t, err, "Error parsing commands in testCase %s", testCase.name)
529 expectedAsYaml, err := yaml.Marshal(testCase.expectedCommands)
530 assert.NilError(t, err, "Error parsing exception to yaml in testCase %s", testCase.name)
531 assert.Equal(t, string(commandsAsYaml), string(expectedAsYaml), "Unexpected commands in testCase %s", testCase.name)
532 })
533 }
534}
535
536type parseTestCase struct {
537 name string

Callers

nothing calls this directly

Calls 12

LoadWithParserMethod · 0.95
NewFunction · 0.92
NewCommandsParserFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
ConfigMethod · 0.65
FatalMethod · 0.45
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected