-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split e2e tests into 2 packages, vm and container (#150)
## Summary PR fixes #142 (comment) by splitting container tests and vm tests into different binaries (i.e., different packages) to make sure that the former is run before the latter. The package-level comment of the `e2e` package provides more details, so reading it first may make reviewing this PR easier. ## License Acceptance By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Hsing-Yu (David) Chen <[email protected]>
- Loading branch information
1 parent
bfdaf56
commit 8cacb1f
Showing
10 changed files
with
133 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package e2e is created because: | ||
// | ||
// During test setup, SetupLocalRegistry is called, | ||
// and container tests need to be run before VM tests | ||
// so that the local registry won't be removed by VM tests, | ||
// and container tests can use the images stored in it. | ||
// | ||
// However, by default Ginkgo does not guarantee the order in which specs run [1], | ||
// and Ginkgo doc says that "You should only ever call RunSpecs once" [2], | ||
// which means that we need two binaries that run VM tests and container tests respectively. | ||
// | ||
// We could add ginkgo.Ordered to the top level Ginkgo container, | ||
// but that will make every single spec to run in the order they are defined: | ||
// "Any container nodes nested within a container node will automatically be considered Ordered | ||
// and there is no way to mark a node within an Ordered container as "not Ordered"" [1], | ||
// and we don't want that because it can hide implicit dependencies among tests, | ||
// while each test should be independent unless specially designed. | ||
// | ||
// As a result, we split the tests into `e2e/vm` and `e2e/container` packages | ||
// and extract the common logic into this package. | ||
// | ||
// [1] https://onsi.github.io/ginkgo/#ordered-containers. | ||
// [2] https://onsi.github.io/ginkgo/#mental-model-go-modules-packages-and-tests | ||
package e2e | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/runfinch/common-tests/option" | ||
) | ||
|
||
// InstalledTestSubject is the test subject when Finch is installed. | ||
const InstalledTestSubject = "finch" | ||
|
||
// Installed indicates whether the tests are run against installed application. | ||
var Installed = flag.Bool("installed", false, "the flag to show whether the tests are run against installed application") | ||
|
||
// CreateOption creates an option for running e2e tests. | ||
func CreateOption() (*option.Option, error) { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get the current working directory: %w", err) | ||
} | ||
|
||
subject := filepath.Join(wd, "../../_output/bin/finch") | ||
if *Installed { | ||
subject = InstalledTestSubject | ||
} | ||
|
||
o, err := option.New([]string{subject}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize a testing option: %w", err) | ||
} | ||
return o, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package vm runs tests related to the virtual machine. | ||
package vm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
"github.com/runfinch/common-tests/command" | ||
|
||
"github.com/runfinch/finch/e2e" | ||
) | ||
|
||
const ( | ||
virtualMachineRootCmd = "vm" | ||
) | ||
|
||
//nolint:paralleltest // TestVM is like TestMain for the VM-related tests. | ||
func TestVM(t *testing.T) { | ||
const description = "Finch Virtual Machine E2E Tests" | ||
|
||
o, err := e2e.CreateOption() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// The VM should be spined up in SynchronizedBeforeSuite of e2e/container. | ||
ginkgo.SynchronizedAfterSuite(func() { | ||
command.New(o, "vm", "stop").WithTimeoutInSeconds(60).Run() | ||
command.New(o, "vm", "remove").WithTimeoutInSeconds(60).Run() | ||
}, func() {}) | ||
|
||
ginkgo.Describe("", func() { | ||
testVMLifecycle(o) | ||
testAdditionalDisk(o) | ||
testConfig(o, *e2e.Installed) | ||
testVersion(o) | ||
}) | ||
|
||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
ginkgo.RunSpecs(t, description) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters