-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework cmds so they are inline with cobra examples
Signed-off-by: Itxaka <[email protected]>
- Loading branch information
Showing
8 changed files
with
212 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: 'run enki unit tests' | ||
|
||
on: | ||
pull_request: | ||
|
||
concurrency: | ||
group: enki-${{ github.ref || github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: earthly/actions/setup-earthly@v1 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Build | ||
run: cd tools-image/enki && earthly -P +test |
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,19 @@ | ||
VERSION 0.7 | ||
|
||
# renovate: datasource=docker depName=golang | ||
ARG --global GO_VERSION=1.20-alpine3.18 | ||
|
||
test: | ||
FROM golang:$GO_VERSION | ||
RUN apk add rsync gcc musl-dev docker jq | ||
WORKDIR /build | ||
COPY . . | ||
RUN go mod download | ||
ARG TEST_PATHS=./... | ||
ARG LABEL_FILTER= | ||
ENV CGO_ENABLED=1 | ||
# Some test require the docker sock exposed | ||
WITH DOCKER | ||
RUN go run github.com/onsi/ginkgo/v2/ginkgo run --label-filter "$LABEL_FILTER" -v --fail-fast --race --covermode=atomic --coverprofile=coverage.out --coverpkg=github.com/rancher/elemental-cli/... -p -r $TEST_PATHS | ||
END | ||
SAVE ARTIFACT coverage.out AS LOCAL coverage.out |
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,70 @@ | ||
/* | ||
Copyright © 2022 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var _ = Describe("BuildISO", Label("iso", "cmd"), func() { | ||
var buf *bytes.Buffer | ||
BeforeEach(func() { | ||
buf = new(bytes.Buffer) | ||
rootCmd.SetOut(buf) | ||
rootCmd.SetErr(buf) | ||
}) | ||
AfterEach(func() { | ||
viper.Reset() | ||
}) | ||
It("Errors out if no rootfs sources are defined", Label("flags"), func() { | ||
_, _, err := executeCommandC(rootCmd, "build-iso") | ||
fmt.Println(buf) | ||
Expect(err).ToNot(BeNil()) | ||
Expect(err.Error()).To(ContainSubstring("rootfs source image for building ISO was not provided")) | ||
}) | ||
It("Errors out if rootfs is a non valid argument", Label("flags"), func() { | ||
_, _, err := executeCommandC(rootCmd, "build-iso", "/no/image/reference") | ||
Expect(err).ToNot(BeNil()) | ||
Expect(err.Error()).To(ContainSubstring("invalid image reference")) | ||
}) | ||
It("Errors out if overlay roofs path does not exist", Label("flags"), func() { | ||
_, _, err := executeCommandC( | ||
rootCmd, "build-iso", "system/cos", "--overlay-rootfs", "/nonexistingpath", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect(err.Error()).To(ContainSubstring("Invalid path")) | ||
}) | ||
It("Errors out if overlay uefi path does not exist", Label("flags"), func() { | ||
_, _, err := executeCommandC( | ||
rootCmd, "build-iso", "someimage:latest", "--overlay-uefi", "/nonexistingpath", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect(err.Error()).To(ContainSubstring("Invalid path")) | ||
}) | ||
It("Errors out if overlay iso path does not exist", Label("flags"), func() { | ||
_, _, err := executeCommandC( | ||
rootCmd, "build-iso", "some/image:latest", "--overlay-iso", "/nonexistingpath", | ||
) | ||
Expect(err).ToNot(BeNil()) | ||
Expect(err.Error()).To(ContainSubstring("Invalid path")) | ||
}) | ||
}) |
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,29 @@ | ||
/* | ||
Copyright © 2021 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestWhitebox(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "CLI whitebox test suite") | ||
} |
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,53 @@ | ||
/* | ||
Copyright © 2021 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func executeCommandC(cmd *cobra.Command, args ...string) (c *cobra.Command, output string, err error) { | ||
// Set args to command | ||
cmd.SetArgs(args) | ||
// store old stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
// Change stdout to our pipe | ||
os.Stdout = w | ||
// run the command | ||
c, err = cmd.ExecuteC() | ||
if err != nil { | ||
// Remember to restore stdout! | ||
os.Stdout = oldStdout | ||
return nil, "", err | ||
} | ||
err = w.Close() | ||
if err != nil { | ||
// Remember to restore stdout! | ||
os.Stdout = oldStdout | ||
return nil, "", err | ||
} | ||
// Read output from our pipe | ||
out, _ := ioutil.ReadAll(r) | ||
// restore stdout | ||
os.Stdout = oldStdout | ||
|
||
return c, string(out), 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