github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/all_doc_en_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 TestAllDocEn(t *testing.T) {
    14  	if len(PipelineFunctionDocs) != len(PipelineFunctionDocsEN) {
    15  		t.Fatal("len(PipelineFunctionDocs) != len(PipelineFunctionDocsEN)")
    16  	}
    17  	protoPrefix, descPrefix := "Function prototype: ", "Function description: "
    18  	funcNameMap := map[string]bool{}
    19  	for name := range PipelineFunctionDocsEN {
    20  		funcNameMap[strings.TrimSuffix(name, "()")] = true
    21  	}
    22  	for fn := range FuncsMap {
    23  		if fn == "json_all" ||
    24  			fn == "default_time_with_fmt" ||
    25  			fn == "expr" ||
    26  			fn == "vaild_json" {
    27  			continue
    28  		}
    29  		if _, has := funcNameMap[fn]; !has {
    30  			t.Errorf("func %s exists in FuncsMap but not in PipelineFunctionDocs", fn)
    31  		}
    32  	}
    33  	for fn, plDoc := range PipelineFunctionDocsEN {
    34  		lines := strings.Split(plDoc.Doc, "\n")
    35  		var hasProto, hasDesc bool
    36  		for _, line := range lines {
    37  			if strings.HasPrefix(line, protoPrefix) {
    38  				hasProto = true
    39  			}
    40  			if strings.HasPrefix(line, descPrefix) {
    41  				hasDesc = true
    42  			}
    43  		}
    44  		// These fields are needed by front-end.
    45  		if !hasDesc {
    46  			t.Errorf("%s does not contain '%s'", fn, protoPrefix)
    47  		}
    48  		if !hasProto {
    49  			t.Errorf("%s does not contain '%s'", fn, descPrefix)
    50  		}
    51  	}
    52  }