github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/dependencies_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package juju_test
     5  
     6  import (
     7  	"go/build"
     8  	"io/ioutil"
     9  	"path/filepath"
    10  	"strings"
    11  	"testing"
    12  
    13  	jc "github.com/juju/testing/checkers"
    14  	gc "gopkg.in/check.v1"
    15  )
    16  
    17  func Test(t *testing.T) {
    18  	gc.TestingT(t)
    19  }
    20  
    21  type dependenciesTest struct{}
    22  
    23  var _ = gc.Suite(&dependenciesTest{})
    24  
    25  func projectRoot(c *gc.C) string {
    26  	p, err := build.Import("github.com/juju/juju", "", build.FindOnly)
    27  	c.Assert(err, jc.ErrorIsNil)
    28  	return p.Dir
    29  }
    30  
    31  func (*dependenciesTest) TestDependenciesTsvFormat(c *gc.C) {
    32  	filename := filepath.Join(projectRoot(c), "dependencies.tsv")
    33  	content, err := ioutil.ReadFile(filename)
    34  	c.Assert(err, jc.ErrorIsNil)
    35  
    36  	for _, line := range strings.Split(string(content), "\n") {
    37  		if line == "" {
    38  			continue
    39  		}
    40  		segments := strings.Split(line, "\t")
    41  		c.Assert(segments, gc.HasLen, 4)
    42  		for _, seg := range segments {
    43  			c.Assert(strings.HasPrefix(seg, " "), jc.IsFalse)
    44  			c.Assert(strings.HasSuffix(seg, " "), jc.IsFalse)
    45  		}
    46  	}
    47  }