Skip to content

Commit

Permalink
test: Run e2e/integration test suites only by setting TEST_SUITE=xxx
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Oct 29, 2020
1 parent b090ba5 commit 1a18f11
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 62 deletions.
25 changes: 25 additions & 0 deletions tests/e2e/buildtag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

// +build e2e

package e2e

import (
"go.ligato.io/vpp-agent/v3/tests/testutils"
)

func init() {
testutils.SetTestSuite("e2e")
}
10 changes: 5 additions & 5 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

govppcore "git.fd.io/govpp.git/core"
"github.com/sirupsen/logrus"

"go.ligato.io/vpp-agent/v3/tests/testutils"
)

var (
Expand All @@ -41,10 +43,8 @@ func TestMain(m *testing.M) {
if *debug {
govppcore.SetLogLevel(logrus.DebugLevel)
}
if os.Getenv("TRAVIS") != "" {
log.Println("skipping e2e tests for Travis")
os.Exit(0)
if testutils.RunTestSuite("e2e") {
result := m.Run()
os.Exit(result)
}
result := m.Run()
os.Exit(result)
}
2 changes: 1 addition & 1 deletion tests/e2e/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ go build -o ./tests/e2e/agentctl.test \

# Compile testing suite
go test -c -o ./tests/e2e/e2e.test \
-tags 'osusergo netgo' \
-tags 'osusergo netgo e2e' \
-ldflags '-w -s -extldflags "-static"' \
./tests/e2e

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ imgname="vpp-agent-integration-tests"

# Compile testing suite
go test -c -o ./tests/integration/integration.test \
-tags 'osusergo netgo' \
-tags 'osusergo netgo integration' \
-ldflags '-w -s -extldflags "-static"' \
./tests/integration/...

Expand Down
25 changes: 25 additions & 0 deletions tests/integration/vpp/buildtag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

// +build integration

package vpp

import (
testutils "go.ligato.io/vpp-agent/v3/tests/testutils"
)

func init() {
testutils.SetTestSuite("integration")
}
8 changes: 6 additions & 2 deletions tests/integration/vpp/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

govppcore "git.fd.io/govpp.git/core"
"github.com/sirupsen/logrus"

testutils "go.ligato.io/vpp-agent/v3/tests/testutils"
)

var (
Expand All @@ -39,6 +41,8 @@ func TestMain(m *testing.M) {
if *debug {
govppcore.SetLogLevel(logrus.DebugLevel)
}
result := m.Run()
os.Exit(result)
if testutils.RunTestSuite("integration") {
result := m.Run()
os.Exit(result)
}
}
53 changes: 0 additions & 53 deletions tests/integration/vpp_integration.sh

This file was deleted.

43 changes: 43 additions & 0 deletions tests/testutils/testsuite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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 testutils

import (
"log"
"os"
"strings"
)

func TestSuite() string {
return os.Getenv("TEST_SUITE")
}

func IsRunningTestSuite(suite string) bool {
return strings.EqualFold(TestSuite(), suite)
}

func SetTestSuite(suite string) {
if err := os.Setenv("TEST_SUITE", suite); err != nil {
log.Panicf("error setting TEST_SUITE=%q: %v", suite, err)
}
}

func RunTestSuite(suite string) bool {
if !IsRunningTestSuite(suite) {
log.Printf("skip running test suite: %[1]s (set TEST_SUITE=%[1]s to run)", suite)
return false
}
return true
}

0 comments on commit 1a18f11

Please sign in to comment.