0

I'm running some tests in golang and I want to avoid running the slow ones, for example this one uses bcrypt so it's slow:

// +build slow
package services

import (
    "testing"
    "testing/quick"
)

// using bcrypt takes too much time, reduce the number of iterations.
var config = &quick.Config{MaxCount: 20}

func TestSignaturesAreSame(t *testing.T) {
    same := func(simple string) bool {
        result, err := Encrypt(simple)
        success := err == nil && ComparePassWithHash(simple, result)
        return success
    }

    if err := quick.Check(same, config); err != nil {
        t.Error(err)
    }
}

To avoid running this in every iteration I've set up the // +build slow flag. This should only run when doing go test -tags slow but unfortunately it's running every time (the -v flag shows it's running).

Any idea what's wrong?

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • 1
    "To distinguish build constraints from package documentation, a series of build constraints must be followed by a blank line." https://golang.org/pkg/go/build/ – JimB Mar 10 '16 at 18:57
  • 1
    I think package testing already has a "short" mode triggered with -short. – Volker Mar 10 '16 at 19:27

1 Answers1

5

Your // +build slow needs to be followed by a blank line

To distinguish build constraints from package documentation, a series of build constraints must be followed by a blank line.

visit Build Constraints

marco.m
  • 4,573
  • 2
  • 26
  • 41
animal
  • 230
  • 1
  • 4