github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/extension/framework/framework_test.go (about)

     1  // Copyright (C) 2015 NTT Innovation Institute, Inc.
     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
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package framework
    17  
    18  import (
    19  	"fmt"
    20  	"io/ioutil"
    21  	"os"
    22  	"testing"
    23  	"time"
    24  
    25  	"github.com/cloudwan/gohan/util"
    26  	. "github.com/onsi/gomega"
    27  )
    28  
    29  func TestGetTestFiles(t *testing.T) {
    30  	RegisterTestingT(t)
    31  
    32  	rootDir, err := ioutil.TempDir(os.TempDir(), fmt.Sprint(time.Now().UnixNano()))
    33  	Expect(err).ToNot(HaveOccurred())
    34  	defer os.RemoveAll(rootDir)
    35  
    36  	leftDir, err := ioutil.TempDir(rootDir, fmt.Sprint(time.Now().UnixNano()))
    37  	Expect(err).ToNot(HaveOccurred())
    38  
    39  	rightDir, err := ioutil.TempDir(rootDir, fmt.Sprint(time.Now().UnixNano()))
    40  	Expect(err).ToNot(HaveOccurred())
    41  
    42  	deepDir, err := ioutil.TempDir(leftDir, fmt.Sprint(time.Now().UnixNano()))
    43  	Expect(err).ToNot(HaveOccurred())
    44  
    45  	testFile1, err := util.TempFile(rootDir, "test_", ".js")
    46  	Expect(err).ToNot(HaveOccurred())
    47  	defer testFile1.Close()
    48  
    49  	testFile2, err := util.TempFile(rightDir, "test_", ".js")
    50  	Expect(err).ToNot(HaveOccurred())
    51  	defer testFile2.Close()
    52  
    53  	testFile3, err := util.TempFile(deepDir, "test_", ".js")
    54  	Expect(err).ToNot(HaveOccurred())
    55  	defer testFile3.Close()
    56  
    57  	irrelevantFile, err := util.TempFile(leftDir, "irrelevant", ".js")
    58  	Expect(err).ToNot(HaveOccurred())
    59  	defer irrelevantFile.Close()
    60  
    61  	args := []string{rootDir}
    62  	tests := getTestFiles(args)
    63  
    64  	Expect(tests).To(ConsistOf(testFile1.Name(), testFile2.Name(), testFile3.Name()))
    65  }