github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/docker/initializer_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/wawandco/ox/plugins/base/new"
    10  )
    11  
    12  func TestInitilizer(t *testing.T) {
    13  	t.Run("dockerFileDoesNotExist", func(t *testing.T) {
    14  
    15  		root := t.TempDir()
    16  		err := os.Chdir(root)
    17  		if err != nil {
    18  			t.Error("could not change to temp directory")
    19  		}
    20  
    21  		i := Initializer{}
    22  		ctx := context.Background()
    23  		options := new.Options{
    24  			Folder: filepath.Join(root),
    25  		}
    26  
    27  		err = i.Initialize(ctx, options)
    28  		if err != nil {
    29  			t.Fatalf("error should be nil, got %v", err)
    30  		}
    31  
    32  		rootDoc := filepath.Join(root, ".dockerignore")
    33  		rootFile := filepath.Join(root, "Dockerfile")
    34  
    35  		_, err = os.Stat(rootDoc)
    36  
    37  		if os.IsNotExist(err) {
    38  			t.Fatalf("Did not create .dockerignore file , %v", err)
    39  		}
    40  		_, err = os.Stat(rootFile)
    41  
    42  		if os.IsNotExist(err) {
    43  			t.Fatalf("Did not create  Dockerfile file , %v", err)
    44  		}
    45  	})
    46  
    47  }