github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/all_doc_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  package funcs
     7  
     8  import (
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  func TestAllDoc(t *testing.T) {
    14  	protoPrefix, descPrefix := "函数原型:", "函数说明:"
    15  	funcNameMap := map[string]bool{}
    16  	for name := range PipelineFunctionDocs {
    17  		funcNameMap[strings.TrimSuffix(name, "()")] = true
    18  	}
    19  	for fn := range FuncsMap {
    20  		if fn == "json_all" ||
    21  			fn == "default_time_with_fmt" ||
    22  			fn == "expr" ||
    23  			fn == "vaild_json" {
    24  			continue
    25  		}
    26  		if _, has := funcNameMap[fn]; !has {
    27  			t.Errorf("func %s exists in FuncsMap but not in PipelineFunctionDocs", fn)
    28  		}
    29  	}
    30  	for fn, plDoc := range PipelineFunctionDocs {
    31  		lines := strings.Split(plDoc.Doc, "\n")
    32  		var hasProto, hasDesc bool
    33  		for _, line := range lines {
    34  			if strings.HasPrefix(line, protoPrefix) {
    35  				hasProto = true
    36  			}
    37  			if strings.HasPrefix(line, descPrefix) {
    38  				hasDesc = true
    39  			}
    40  		}
    41  		// These fields are needed by front-end.
    42  		if !hasDesc {
    43  			t.Errorf("%s does not contain '%s'", fn, protoPrefix)
    44  		}
    45  		if !hasProto {
    46  			t.Errorf("%s does not contain '%s'", fn, descPrefix)
    47  		}
    48  	}
    49  }