Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VBoxManage is missing from CI #14

Closed
VoyTechnology opened this issue Oct 30, 2019 · 3 comments
Closed

VBoxManage is missing from CI #14

VoyTechnology opened this issue Oct 30, 2019 · 3 comments
Assignees
Labels

Comments

@VoyTechnology
Copy link
Member

This affects #13 and #11 from what I can see and is blocking the merge of the PRs.

@VoyTechnology VoyTechnology self-assigned this Oct 30, 2019
@nevill
Copy link

nevill commented Nov 1, 2019

It seems this project never had a success build from very beginning. It requires to mock the output VBoxManage to make the test passed.

@VoyTechnology
Copy link
Member Author

VoyTechnology commented Nov 13, 2019

#15 Adds the ability to override the executor, meaning we can mock the output, but that still needs to be done. Right now it works like volkswagen and all tests just pass. I would rather not have each test add to a massive list of elements to the vbm_test.go file, so I would suggest in each test you can specify the output you want.

func mockOutput(out string) {
  defaultExecutor = func(ctx context.Context, so io.Writer, se io.Writer, args ...string) error {
    fmt.Fprint(so, out)
    return nil
  }
}
func TestListMachines(t *testing.T) {
  testCases := map[string]struct{
    out string
    want []*Machine
    wantErr error
  }{
    "empty": {
      "",
      []*Machine{},
      nil
    },
    "single: {
      "\"Test\" {1b2de526-b913-482a-b8aa-dfef87bbb840}",
      []*Machine{&Machine{Name: "Test", UUID: "1b2de526-b913-482a-b8aa-dfef87bbb840"},
      nil,
    },
    "error": {
      "VBoxManage: error: Unknown option: --status",
      []*Machine{},
      ErrUnknownOption,
    },
  }

  for name, tc := range testCases {
    t.Run(name, func(t *testing.T) {
      mockOutput(tc.out)

      ms, err := ListMachines()
      if errors.Is(err, tc.wantErr) {
        t.Errorf("ListMachines() err = %v, want %v", err, tc.wantErr)
      }
      if diff := deep.Equal(ms, tc.want) {
        t.Errorf("ListMachines() = %v, want %v, diff: %v", err, tc.want, diff)
      }
    })
  }
}

@ringods
Copy link
Contributor

ringods commented Dec 4, 2019

#17 fixed this with a full mock setup.

@ringods ringods closed this as completed Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants