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 Oct 29, 2019
1 parent d5badbb commit 7a596e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 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
20 changes: 13 additions & 7 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"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
)
Expand Down Expand Up @@ -49,7 +48,15 @@ func int64Var(p *int64, name string, usage string) {
flag.Int64Var(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")

// Support overriding the default configuration via flags.
Expand Down Expand Up @@ -79,9 +86,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/utils"
Expand Down Expand Up @@ -185,7 +184,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 7a596e1

Please sign in to comment.