Home | History | Annotate | Download | only in blueprint
      1 // Copyright 2018 Google Inc. All rights reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package blueprint
     16 
     17 import "testing"
     18 
     19 func TestGlobCache(t *testing.T) {
     20 	ctx := NewContext()
     21 	ctx.MockFileSystem(map[string][]byte{
     22 		"Blueprints": nil,
     23 		"a/a":        nil,
     24 		"a/b":        nil,
     25 	})
     26 
     27 	// Test a simple glob with no excludes
     28 	matches, err := ctx.glob("a/*", nil)
     29 	if err != nil {
     30 		t.Error("unexpected error", err)
     31 	}
     32 	if len(matches) != 2 || matches[0] != "a/a" || matches[1] != "a/b" {
     33 		t.Error(`expected ["a/a", "a/b"], got`, matches)
     34 	}
     35 
     36 	// Test the same glob with an empty excludes array to make sure
     37 	// excludes=nil does not conflict with excludes=[]string{} in the
     38 	// cache.
     39 	matches, err = ctx.glob("a/*", []string{})
     40 	if err != nil {
     41 		t.Error("unexpected error", err)
     42 	}
     43 	if len(matches) != 2 || matches[0] != "a/a" || matches[1] != "a/b" {
     44 		t.Error(`expected ["a/a", "a/b"], got`, matches)
     45 	}
     46 
     47 	// Test the same glob with a different excludes array
     48 	matches, err = ctx.glob("a/*", []string{"a/b"})
     49 	if err != nil {
     50 		t.Error("unexpected error", err)
     51 	}
     52 	if len(matches) != 1 || matches[0] != "a/a" {
     53 		t.Error(`expected ["a/a"], got`, matches)
     54 	}
     55 }
     56