github.com/gocomu/cli@v0.0.34-0.20200305112720-636c0f622e59/serve_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  
     9  	"gopkg.in/yaml.v3"
    10  )
    11  
    12  func TestServe(t *testing.T) {
    13  	// prepare gocomu.yml
    14  	dir, _ := os.Getwd()
    15  	yamlData := &GocomuYaml{
    16  		Name:        "test",
    17  		Description: "t",
    18  		Version:     "0.0",
    19  		Type:        "cli",
    20  		ServeOutput: "0",
    21  	}
    22  	data, _ := yaml.Marshal(yamlData)
    23  	ioutil.WriteFile("gocomu.yml", data, 0755)
    24  	os.Chdir(dir + "/test")
    25  	t.Run("Run proejctServe()", func(t *testing.T) {
    26  		go projectServe()
    27  		time.Sleep(1 * time.Second)
    28  	})
    29  
    30  	os.Chdir(dir)
    31  	os.Remove(dir + "/test")
    32  
    33  	t.Run("Run reload()", func(t *testing.T) {
    34  		reload("test")
    35  	})
    36  }