PageRenderTime 50ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/helpers/virtualbox/control_test.go

https://gitlab.com/gitlab-org/gitlab-runner
Go | 54 lines | 43 code | 7 blank | 4 comment | 3 complexity | c87a6618a79281f1eef6c7378555696f MD5 | raw file
  1. //go:build !integration
  2. // +build !integration
  3. package virtualbox
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestSnapshotNameRegex(t *testing.T) {
  9. var tests = []struct {
  10. output string
  11. snapshotName string
  12. expectedToFind bool
  13. }{
  14. {`SnapshotName="v1"`, "v1", true},
  15. {`SnapshotName="gitlabrunner"`, "gitlabrunner", true},
  16. {"SnapshotName=\"gitlabrunner\"\nSnapshotUUID=\"UUID\"\n", "gitlabrunner", true},
  17. {"SnapshotName=\"gitlabrunner\"\nSnapshotUUID=\"UUID\"\n", "notpresent", false},
  18. // Windows style \r\n new lines
  19. {"SnapshotName=\"gitlabrunner\"\r\nSnapshotUUID=\"UUID\"\r\n", "gitlabrunner", true},
  20. }
  21. for _, test := range tests {
  22. assert.Equal(t, test.expectedToFind, matchSnapshotName(test.snapshotName, test.output))
  23. }
  24. }
  25. func TestCurrentSnapshotNameRegex(t *testing.T) {
  26. var tests = []struct {
  27. output string
  28. expectedSnapshotName string
  29. expectedToFind bool
  30. }{
  31. {`CurrentSnapshotName="v1"`, "v1", true},
  32. {`CurrentSnapshotName="gitlabrunner"`, "gitlabrunner", true},
  33. {"CurrentSnapshotName=\"gitlabrunner\"\nCurrentSnapshotUUID=\"UUID\"\n", "gitlabrunner", true},
  34. {"CurrentSnapshotName=\"gitlabrunner\"\nCurrentSnapshotUUID=\"UUID\"\n", "notpresent", false},
  35. // Windows style \r\n new lines
  36. {"CurrentSnapshotName=\"gitlabrunner\"\r\nCurrentSnapshotUUID=\"UUID\"\r\n", "gitlabrunner", true},
  37. }
  38. for _, test := range tests {
  39. actual := matchCurrentSnapshotName(test.output)
  40. if test.expectedToFind {
  41. assert.NotNil(t, actual)
  42. assert.Equal(t, test.expectedSnapshotName, actual[1])
  43. return
  44. }
  45. assert.NotEqual(t, test.expectedSnapshotName, actual[1])
  46. }
  47. }