Skip to content

Commit 0db297f

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 769a246 commit 0db297f

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
"time"
2423

2524
"github.com/kubernetes-csi/csi-test/v3/pkg/sanity"
@@ -31,7 +30,6 @@ const (
3130

3231
var (
3332
VERSION = "(dev)"
34-
config = sanity.NewTestConfig()
3533
)
3634

3735
func stringVar(p *string, name string, usage string) {
@@ -54,9 +52,20 @@ func durationVar(p *time.Duration, name string, usage string) {
5452
flag.DurationVar(p, prefix+name, *p, usage)
5553
}
5654

57-
func TestMain(m *testing.M) {
55+
type testing struct {
56+
result int
57+
}
58+
59+
func (t *testing) Fail() {
60+
t.result = 1
61+
}
62+
63+
func main() {
5864
version := flag.Bool("version", false, "print version of this program")
5965

66+
// Get configuration with defaults.
67+
config := sanity.NewTestConfig()
68+
6069
// Support overriding the default configuration via flags.
6170
stringVar(&config.Address, "endpoint", "CSI endpoint")
6271
stringVar(&config.ControllerAddress, "controllerendpoint", "CSI controller endpoint")
@@ -85,9 +94,8 @@ func TestMain(m *testing.M) {
8594
fmt.Printf("--%sendpoint must be provided with an CSI endpoint\n", prefix)
8695
os.Exit(1)
8796
}
88-
os.Exit(m.Run())
89-
}
9097

91-
func TestSanity(t *testing.T) {
92-
sanity.Test(t, config)
98+
t := testing{}
99+
sanity.Test(&t, config)
100+
os.Exit(t.result)
93101
}

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/v3/utils"
@@ -189,7 +188,7 @@ func newTestContext(config *TestConfig) *TestContext {
189188

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

0 commit comments

Comments
 (0)