Skip to content

Commit

Permalink
sanity: turn csi-sanity into normal Go program
Browse files Browse the repository at this point in the history
The advantage is that "go get" works and that the useless "-test.*"
command line parameters are no longer present.
  • Loading branch information
pohly committed Nov 14, 2019
1 parent 769a246 commit 0db297f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions cmd/csi-sanity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ PACKAGE :=$(DIR)/dist/$(APP_NAME)-$(RELEASEVER).$(GOOS).$(ARCH).tar.gz

all: $(APP_NAME)

$(APP_NAME): Makefile sanity_test.go
go test $(LDFLAGS) -c -o $(APP_NAME)
.PHONY: $(APP_NAME)
$(APP_NAME): Makefile
go build $(LDFLAGS) -o $(APP_NAME)

install: $(APP_NAME)
cp $(APP_NAME) $(GOPATH)/bin
Expand Down
24 changes: 16 additions & 8 deletions cmd/csi-sanity/sanity_test.go → cmd/csi-sanity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ 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 sanity
package main

import (
"flag"
"fmt"
"os"
"testing"
"time"

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

var (
VERSION = "(dev)"
config = sanity.NewTestConfig()
)

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

func TestMain(m *testing.M) {
type testing struct {
result int
}

func (t *testing) Fail() {
t.result = 1
}

func main() {
version := flag.Bool("version", false, "print version of this program")

// Get configuration with defaults.
config := sanity.NewTestConfig()

// Support overriding the default configuration via flags.
stringVar(&config.Address, "endpoint", "CSI endpoint")
stringVar(&config.ControllerAddress, "controllerendpoint", "CSI controller endpoint")
Expand Down Expand Up @@ -85,9 +94,8 @@ func TestMain(m *testing.M) {
fmt.Printf("--%sendpoint must be provided with an CSI endpoint\n", prefix)
os.Exit(1)
}
os.Exit(m.Run())
}

func TestSanity(t *testing.T) {
sanity.Test(t, config)
t := testing{}
sanity.Test(&t, config)
os.Exit(t.result)
}
3 changes: 1 addition & 2 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"os/exec"
"strings"
"testing"
"time"

"github.com/kubernetes-csi/csi-test/v3/utils"
Expand Down Expand Up @@ -189,7 +188,7 @@ func newTestContext(config *TestConfig) *TestContext {

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

Expand Down

0 comments on commit 0db297f

Please sign in to comment.