Skip to content

Commit

Permalink
Merge branch 'master' into lint
Browse files Browse the repository at this point in the history
* master:
  Skip some tests in case of no internet connection
  • Loading branch information
iwataka committed Jul 26, 2018
2 parents d38112a + 2a839d4 commit f855037
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"

gomock "github.com/golang/mock/gomock"
"github.com/iwataka/anaconda"
Expand Down Expand Up @@ -88,6 +90,7 @@ func init() {
}

func TestTwitterColsPage(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testTwitterCols(t, testTwitterColsPage)
}

Expand Down Expand Up @@ -318,6 +321,7 @@ func testPostConfig(t *testing.T, f func(*testing.T, string, *agouti.Page, *sync
}

func TestPostConfigWithoutModification(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigWithoutModification)
}

Expand Down Expand Up @@ -345,6 +349,7 @@ func testPostConfigWithoutModification(
}

func TestPostConfigDelete(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigDelete)
}

Expand All @@ -371,6 +376,7 @@ func testPostConfigDelete(
}

func TestPostConfigSingleDelete(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigSingleDelete)
}

Expand All @@ -395,6 +401,7 @@ func testPostConfigSingleDelete(
}

func TestPostConfigDoubleDelete(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigDoubleDelete)
}

Expand Down Expand Up @@ -422,6 +429,7 @@ func testPostConfigDoubleDelete(
}

func TestPostConfigNameError(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigNameError)
}

Expand Down Expand Up @@ -468,6 +476,7 @@ func testPostConfigNameError(
}

func TestPostConfigTagsInput(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)
testPostConfig(t, testPostConfigTagsInput)
}

Expand All @@ -477,10 +486,6 @@ func testPostConfigTagsInput(
page *agouti.Page,
wg *sync.WaitGroup,
) {
// _, err := net.DialTimeout("tcp", "cdnjs.cloudflare.com:https", 30*time.Second)
// if err != nil {
// t.Skip("Skip because network is unavailable: ", err)
// }
t.Skip("Skip because phantom.js doesn't support tagsinput currently.")

assert.NoError(t, page.Navigate(url))
Expand Down Expand Up @@ -561,6 +566,8 @@ func testPostConfigAdd(
}

func TestIndexPage(t *testing.T) {
skipIfDialTimeout(t, "twitter.com", "https", 30*time.Second)

twitterAPIMock := generateTwitterAPIMock(t, anaconda.User{ScreenName: "foo"}, nil)
tmpTwitterAPI := serverTestUserSpecificData.twitterAPI
defer func() { serverTestUserSpecificData.twitterAPI = tmpTwitterAPI }()
Expand Down Expand Up @@ -687,3 +694,11 @@ func testIfAssetsNotExist(t *testing.T, f func(t *testing.T)) {

f(t)
}

// TODO: Show skip warning even when executing `go test` without `-v` argument
func skipIfDialTimeout(t *testing.T, domain, protocol string, timeout time.Duration) {
_, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", domain, protocol), timeout)
if err != nil {
t.Skip("Skip because network is unavailable: ", err)
}
}

0 comments on commit f855037

Please sign in to comment.