Skip to content

Commit 29c009c

Browse files
committed
sanity: turn csi-sanity into normal Go program
The advantage is that "go get" works and that the useless "-test.*" command line parameters are no longer present.
1 parent d5badbb commit 29c009c

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

cmd/csi-sanity/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ PACKAGE :=$(DIR)/dist/$(APP_NAME)-$(RELEASEVER).$(GOOS).$(ARCH).tar.gz
2222

2323
all: $(APP_NAME)
2424

25-
$(APP_NAME): Makefile sanity_test.go
26-
go test $(LDFLAGS) -c -o $(APP_NAME)
25+
.PHONY: $(APP_NAME)
26+
$(APP_NAME): Makefile
27+
go build $(LDFLAGS) -o $(APP_NAME)
2728

2829
install: $(APP_NAME)
2930
cp $(APP_NAME) $(GOPATH)/bin

cmd/csi-sanity/sanity_test.go renamed to cmd/csi-sanity/main.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package sanity
16+
package main
1717

1818
import (
1919
"flag"
2020
"fmt"
2121
"os"
22-
"testing"
2322

2423
"github.com/kubernetes-csi/csi-test/pkg/sanity"
2524
)
@@ -30,7 +29,6 @@ const (
3029

3130
var (
3231
VERSION = "(dev)"
33-
config = sanity.NewTestConfig()
3432
)
3533

3634
func stringVar(p *string, name string, usage string) {
@@ -49,9 +47,20 @@ func int64Var(p *int64, name string, usage string) {
4947
flag.Int64Var(p, prefix+name, *p, usage)
5048
}
5149

52-
func TestMain(m *testing.M) {
50+
type testing struct {
51+
result int
52+
}
53+
54+
func (t *testing) Fail() {
55+
t.result = 1
56+
}
57+
58+
func main() {
5359
version := flag.Bool("version", false, "print version of this program")
5460

61+
// Get configuration with defaults.
62+
config := sanity.NewTestConfig()
63+
5564
// Support overriding the default configuration via flags.
5665
stringVar(&config.Address, "endpoint", "CSI endpoint")
5766
stringVar(&config.ControllerAddress, "controllerendpoint", "CSI controller endpoint")
@@ -79,9 +88,8 @@ func TestMain(m *testing.M) {
7988
fmt.Printf("--%sendpoint must be provided with an CSI endpoint\n", prefix)
8089
os.Exit(1)
8190
}
82-
os.Exit(m.Run())
83-
}
8491

85-
func TestSanity(t *testing.T) {
86-
sanity.Test(t, config)
92+
t := testing{}
93+
sanity.Test(&t, config)
94+
os.Exit(t.result)
8795
}

pkg/sanity/sanity.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"os"
2525
"os/exec"
2626
"strings"
27-
"testing"
2827
"time"
2928

3029
"github.com/kubernetes-csi/csi-test/utils"
@@ -185,7 +184,7 @@ func newTestContext(config *TestConfig) *TestContext {
185184

186185
// Test will test the CSI driver at the specified address by
187186
// setting up a Ginkgo suite and running it.
188-
func Test(t *testing.T, config TestConfig) {
187+
func Test(t GinkgoTestingT, config TestConfig) {
189188
sc := GinkgoTest(&config)
190189
RegisterFailHandler(Fail)
191190

0 commit comments

Comments
 (0)