github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/gen/gen_test.go (about)

     1  package gen
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/lmorg/murex/test/count"
     8  	docgen "github.com/lmorg/murex/utils/docgen/api"
     9  )
    10  
    11  type logger struct {
    12  	t *testing.T
    13  }
    14  
    15  func (l logger) Write(b []byte) (int, error) {
    16  	l.t.Log(string(b))
    17  	return len(b), nil
    18  }
    19  
    20  // TestDocgenConfigTemplates tests the config YAML and template files are all
    21  // valid and the project can render
    22  func TestDocgenConfigTemplates(t *testing.T) {
    23  	count.Tests(t, 1)
    24  
    25  	if _, err := os.Stat("gen/docgen.yaml"); os.IsNotExist(err) {
    26  		os.Chdir("..")
    27  	}
    28  
    29  	l := logger{t: t}
    30  	docgen.SetLogger(l)
    31  
    32  	docgen.ReadOnly = true
    33  	err := docgen.ReadConfig("gen/docgen.yaml")
    34  	if err != nil {
    35  		t.Error(err)
    36  	}
    37  
    38  	err = docgen.Render()
    39  	if err != nil {
    40  		t.Error(err)
    41  	}
    42  }