Use require.NoError where appropriate
This commit is contained in:
parent
57ab50a4a7
commit
8f414883a7
4 changed files with 23 additions and 23 deletions
|
@ -35,7 +35,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func TestFetchall_valid(t *testing.T) {
|
func TestFetchall_valid(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
type endpoint string
|
type endpoint string
|
||||||
|
|
||||||
|
@ -73,14 +73,14 @@ func TestFetchall_valid(t *testing.T) {
|
||||||
cmd.Stdout = nil
|
cmd.Stdout = nil
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
require.Nil(t, cmd.Run())
|
require.NoError(t, cmd.Run())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchall_multipleURLs(t *testing.T) {
|
func TestFetchall_multipleURLs(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var fooHit, barHit int32
|
var fooHit, barHit int32
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ func TestFetchall_multipleURLs(t *testing.T) {
|
||||||
cmd.Stdout = nil
|
cmd.Stdout = nil
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
require.Nil(t, cmd.Run())
|
require.NoError(t, cmd.Run())
|
||||||
|
|
||||||
require.Equal(t, int32(1), atomic.LoadInt32(&fooHit))
|
require.Equal(t, int32(1), atomic.LoadInt32(&fooHit))
|
||||||
require.Equal(t, int32(1), atomic.LoadInt32(&barHit))
|
require.Equal(t, int32(1), atomic.LoadInt32(&barHit))
|
||||||
|
@ -109,7 +109,7 @@ func TestFetchall_multipleURLs(t *testing.T) {
|
||||||
|
|
||||||
func TestFetchall_malformed(t *testing.T) {
|
func TestFetchall_malformed(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
hit := int32(0)
|
hit := int32(0)
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -123,14 +123,14 @@ func TestFetchall_malformed(t *testing.T) {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.True(t, atomic.LoadInt32(&hit) >= 2)
|
require.True(t, atomic.LoadInt32(&hit) >= 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchall_concurrency(t *testing.T) {
|
func TestFetchall_concurrency(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(fetchallImportPath)
|
binary, err := binCache.GetBinary(fetchallImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var callOrder []time.Duration
|
var callOrder []time.Duration
|
||||||
|
@ -140,7 +140,7 @@ func TestFetchall_concurrency(t *testing.T) {
|
||||||
require.NotEmpty(t, s)
|
require.NotEmpty(t, s)
|
||||||
|
|
||||||
d, err := time.ParseDuration(s)
|
d, err := time.ParseDuration(s)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
time.Sleep(d)
|
time.Sleep(d)
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func TestFetchall_concurrency(t *testing.T) {
|
||||||
cmd.Stdout = nil
|
cmd.Stdout = nil
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
require.Nil(t, cmd.Run())
|
require.NoError(t, cmd.Run())
|
||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
|
@ -29,11 +29,11 @@ func listDirs(dir string) ([]string, error) {
|
||||||
|
|
||||||
func Test_testSubmission_correct(t *testing.T) {
|
func Test_testSubmission_correct(t *testing.T) {
|
||||||
testDirs, err := listDirs("../testdata/submissions/correct")
|
testDirs, err := listDirs("../testdata/submissions/correct")
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, dir := range testDirs {
|
for _, dir := range testDirs {
|
||||||
absDir, err := filepath.Abs(dir)
|
absDir, err := filepath.Abs(dir)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
problem := path.Base(absDir)
|
problem := path.Base(absDir)
|
||||||
t.Run(problem, func(t *testing.T) {
|
t.Run(problem, func(t *testing.T) {
|
||||||
studentRepo := path.Join(absDir, "student")
|
studentRepo := path.Join(absDir, "student")
|
||||||
|
@ -46,11 +46,11 @@ func Test_testSubmission_correct(t *testing.T) {
|
||||||
|
|
||||||
func Test_testSubmission_incorrect(t *testing.T) {
|
func Test_testSubmission_incorrect(t *testing.T) {
|
||||||
testDirs, err := listDirs("../testdata/submissions/incorrect")
|
testDirs, err := listDirs("../testdata/submissions/incorrect")
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, dir := range testDirs {
|
for _, dir := range testDirs {
|
||||||
absDir, err := filepath.Abs(dir)
|
absDir, err := filepath.Abs(dir)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
problem := path.Base(absDir)
|
problem := path.Base(absDir)
|
||||||
t.Run(problem, func(t *testing.T) {
|
t.Run(problem, func(t *testing.T) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func TestUrlFetch_valid(t *testing.T) {
|
func TestUrlFetch_valid(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(urlfetchImportPath)
|
binary, err := binCache.GetBinary(urlfetchImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
type endpoint string
|
type endpoint string
|
||||||
type response string
|
type response string
|
||||||
|
@ -91,7 +91,7 @@ func TestUrlFetch_valid(t *testing.T) {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
data, err := cmd.Output()
|
data, err := cmd.Output()
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, r := range tc.expected {
|
for _, r := range tc.expected {
|
||||||
require.True(t, bytes.Contains(data, []byte(r)),
|
require.True(t, bytes.Contains(data, []byte(r)),
|
||||||
|
@ -104,7 +104,7 @@ func TestUrlFetch_valid(t *testing.T) {
|
||||||
|
|
||||||
func TestUrlFetch_malformed(t *testing.T) {
|
func TestUrlFetch_malformed(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(urlfetchImportPath)
|
binary, err := binCache.GetBinary(urlfetchImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _ = w.Write([]byte("success"))
|
_, _ = w.Write([]byte("success"))
|
||||||
|
@ -141,7 +141,7 @@ func TestUrlFetch_malformed(t *testing.T) {
|
||||||
|
|
||||||
func TestUrlFetch_order(t *testing.T) {
|
func TestUrlFetch_order(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(urlfetchImportPath)
|
binary, err := binCache.GetBinary(urlfetchImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ func TestUrlFetch_order(t *testing.T) {
|
||||||
cmd.Stdout = nil
|
cmd.Stdout = nil
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
require.Nil(t, cmd.Run())
|
require.NoError(t, cmd.Run())
|
||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func TestWordCount(t *testing.T) {
|
func TestWordCount(t *testing.T) {
|
||||||
binary, err := binCache.GetBinary(wordcountImportPath)
|
binary, err := binCache.GetBinary(wordcountImportPath)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
type counts map[string]int64
|
type counts map[string]int64
|
||||||
type files []string
|
type files []string
|
||||||
|
@ -77,7 +77,7 @@ b`,
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
// Create temp directory.
|
// Create temp directory.
|
||||||
testDir, err := ioutil.TempDir("", "wordcount-testdata-")
|
testDir, err := ioutil.TempDir("", "wordcount-testdata-")
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
defer func() { _ = os.RemoveAll(testDir) }()
|
defer func() { _ = os.RemoveAll(testDir) }()
|
||||||
|
|
||||||
// Create test files in temp directory.
|
// Create test files in temp directory.
|
||||||
|
@ -85,7 +85,7 @@ b`,
|
||||||
for _, f := range tc.files {
|
for _, f := range tc.files {
|
||||||
file := path.Join(testDir, testtool.RandomName())
|
file := path.Join(testDir, testtool.RandomName())
|
||||||
err = ioutil.WriteFile(file, []byte(f), 0644)
|
err = ioutil.WriteFile(file, []byte(f), 0644)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ b`,
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Parse output and compare with an expected one.
|
// Parse output and compare with an expected one.
|
||||||
counts, err := parseStdout(output)
|
counts, err := parseStdout(output)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.True(t, reflect.DeepEqual(tc.expected, counts),
|
require.True(t, reflect.DeepEqual(tc.expected, counts),
|
||||||
fmt.Sprintf("expected: %v; got: %v", tc.expected, counts))
|
fmt.Sprintf("expected: %v; got: %v", tc.expected, counts))
|
||||||
|
|
Loading…
Reference in a new issue