TODO: Finish this test!
(t *testing.T)
| 479 | |
| 480 | // TODO: Finish this test! |
| 481 | func 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 | |
| 536 | type parseTestCase struct { |
| 537 | name string |
nothing calls this directly
no test coverage detected