Skip to content

Commit d53f998

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 d53f998

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
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

+13-7
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
)
@@ -49,7 +48,15 @@ func int64Var(p *int64, name string, usage string) {
4948
flag.Int64Var(p, prefix+name, *p, usage)
5049
}
5150

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

5562
// Support overriding the default configuration via flags.
@@ -79,9 +86,8 @@ func TestMain(m *testing.M) {
7986
fmt.Printf("--%sendpoint must be provided with an CSI endpoint\n", prefix)
8087
os.Exit(1)
8188
}
82-
os.Exit(m.Run())
83-
}
8489

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

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)