Files
kustomize/cmd/gorepomod/gorepomod_test.go
Karl Isenberg 43868688d5 Use require for Error and NoError
Assert keeps going after failure, but require immediately fails
the tests, making it easier to find the output related to the test
failure, rather than having to comb through a bunch of subsequent
assertion failures. For equality tests, we may or may not want to
continue, but for error checks we almost always want to immediately
fail the test. Exceptions can be changed as-needed.
2024-03-20 13:19:18 -07:00

88 lines
1.8 KiB
Go

// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestListCommand(t *testing.T) {
// Assuming gorepomod is installed
var testCases = map[string]struct {
isFork bool
cmd string
expected string
}{
"upstreamWithLocalFlag": {
isFork: false,
cmd: "cd ../.. && gorepomod list --local",
},
"upstreamWithNoLocalFlag": {
isFork: false,
cmd: "cd ../.. && gorepomod list",
},
"forkWithLocalFlag": {
isFork: true,
cmd: "cd ../.. && gorepomod list --local",
},
"forkWithNoLocalFlag": {
isFork: true,
cmd: "cd ../.. && gorepomod list",
},
}
for _, tc := range testCases {
bash, err := exec.LookPath("bash")
if err != nil {
t.Error("bash not found")
}
out, err := exec.Command(bash, "-c", tc.cmd).Output()
if err != nil {
require.Error(t, err, "exit status 1")
}
assert.Greater(t, len(string(out)), 1)
}
}
func TestPinCommand(t *testing.T) {
// Assuming gorepomod is installed
var testCases = map[string]struct {
isFork bool
cmd string
}{
"upstreamWithLocalFlag": {
isFork: false,
cmd: "cd ../.. && gorepomod pin kyaml --local",
},
"upstreamWithNoLocalFlag": {
isFork: false,
cmd: "cd ../.. && gorepomod pin kyaml",
},
"forkWithLocalFlag": {
isFork: true,
cmd: "cd ../.. && gorepomod pin kyaml --local",
},
"forkWithNoLocalFlag": {
isFork: true,
cmd: "cd ../.. && gorepomod pin kyaml",
},
}
for _, tc := range testCases {
bash, err := exec.LookPath("bash")
if err != nil {
t.Error("bash not found")
}
out, err := exec.Command(bash, "-c", tc.cmd).Output()
if err != nil {
require.Error(t, err, "exit status 1")
}
assert.Greater(t, len(string(out)), 1)
}
}