github.com/git-ogawa/go-dbyml@v1.2.1/dbyml/dockerignore_test.go (about)

     1  package dbyml
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  // Read the content from .dockerignore
    12  func TestReadFile(t *testing.T) {
    13  	pwd, _ := os.Getwd()
    14  	root, _ := filepath.Abs("../")
    15  	os.Chdir(root)
    16  
    17  	excludes, err := ReadDockerignore("testdata/dockerfile_ignore")
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  
    22  	expected := []string{"ignore.txt", "ignore_dir", "*/*tmp*"}
    23  	assert.Equal(t, expected, excludes)
    24  	os.Chdir(pwd)
    25  }
    26  
    27  // Read the content from .dockerignore but it dose not exist.
    28  func TestReadFileEmpty(t *testing.T) {
    29  	pwd, _ := os.Getwd()
    30  	root, _ := filepath.Abs("../")
    31  	os.Chdir(root)
    32  
    33  	excludes, err := ReadDockerignore("testdata/dockerfile_standard")
    34  	if err != nil {
    35  		panic(err)
    36  	}
    37  	assert.Equal(t, []string{}, excludes)
    38  	os.Chdir(pwd)
    39  }