github.com/bhameyie/otto@v0.2.1-0.20160406174117-16052efa52ec/builtin/app/ruby/app_test.go (about)

     1  package rubyapp
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"reflect"
     7  	"sort"
     8  	"testing"
     9  
    10  	"github.com/hashicorp/otto/app"
    11  	"github.com/hashicorp/otto/appfile"
    12  )
    13  
    14  func TestApp_impl(t *testing.T) {
    15  	var _ app.App = new(App)
    16  }
    17  
    18  func TestAppImplicit(t *testing.T) {
    19  	cases := []struct {
    20  		Dir  string
    21  		Deps []string
    22  	}{
    23  		{
    24  			"implicit-none",
    25  			nil,
    26  		},
    27  
    28  		{
    29  			"implicit-redis",
    30  			[]string{"github.com/hashicorp/otto/examples/redis"},
    31  		},
    32  	}
    33  
    34  	for _, tc := range cases {
    35  		errPrefix := fmt.Sprintf("In '%s': ", tc.Dir)
    36  
    37  		// Build our context we send in
    38  		var ctx app.Context
    39  		ctx.Appfile = &appfile.File{Path: filepath.Join("./test-fixtures", tc.Dir, "Appfile")}
    40  
    41  		// Get the implicit file
    42  		var a App
    43  		f, err := a.Implicit(&ctx)
    44  		if err != nil {
    45  			t.Fatalf("%s: %s", errPrefix, err)
    46  		}
    47  		if (len(tc.Deps) == 0) != (f == nil) {
    48  			// Complicated statement above but basically: should be nil if
    49  			// we expected no deps, and should not be nil if we expect deps
    50  			t.Fatalf("%s: deps: %#v\n\ninvalid file: %#v", errPrefix, tc.Deps, f)
    51  		}
    52  		if f == nil {
    53  			continue
    54  		}
    55  
    56  		// Build the deps we got and sort them for determinism
    57  		actual := make([]string, 0, len(f.Application.Dependencies))
    58  		for _, dep := range f.Application.Dependencies {
    59  			actual = append(actual, dep.Source)
    60  		}
    61  		sort.Strings(actual)
    62  		sort.Strings(tc.Deps)
    63  
    64  		// Test
    65  		if !reflect.DeepEqual(actual, tc.Deps) {
    66  			t.Fatalf("%s\n\ngot: %#v\n\nexpected: %#v", errPrefix, actual, tc.Deps)
    67  		}
    68  	}
    69  }