code.gitea.io/gitea@v1.19.3/modules/repository/generate_test.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package repository
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  var giteaTemplate = []byte(`
    13  # Header
    14  
    15  # All .go files
    16  **.go
    17  
    18  # All text files in /text/
    19  text/*.txt
    20  
    21  # All files in modules folders
    22  **/modules/*
    23  `)
    24  
    25  func TestGiteaTemplate(t *testing.T) {
    26  	gt := GiteaTemplate{Content: giteaTemplate}
    27  	assert.Len(t, gt.Globs(), 3)
    28  
    29  	tt := []struct {
    30  		Path  string
    31  		Match bool
    32  	}{
    33  		{Path: "main.go", Match: true},
    34  		{Path: "a/b/c/d/e.go", Match: true},
    35  		{Path: "main.txt", Match: false},
    36  		{Path: "a/b.txt", Match: false},
    37  		{Path: "text/a.txt", Match: true},
    38  		{Path: "text/b.txt", Match: true},
    39  		{Path: "text/c.json", Match: false},
    40  		{Path: "a/b/c/modules/README.md", Match: true},
    41  		{Path: "a/b/c/modules/d/README.md", Match: false},
    42  	}
    43  
    44  	for _, tc := range tt {
    45  		t.Run(tc.Path, func(t *testing.T) {
    46  			match := false
    47  			for _, g := range gt.Globs() {
    48  				if g.Match(tc.Path) {
    49  					match = true
    50  					break
    51  				}
    52  			}
    53  			assert.Equal(t, tc.Match, match)
    54  		})
    55  	}
    56  }