-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathdata_git_repository_file_test.go
98 lines (82 loc) · 3.03 KB
/
data_git_repository_file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//go:build (all || data_sources || git || data_git_repository) && (!exclude_data_sources || !exclude_git || !data_git_repository)
// +build all data_sources git data_git_repository
// +build !exclude_data_sources !exclude_git !data_git_repository
package acceptancetests
import (
"fmt"
"regexp"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccGitRepositoryFile_DataSource(t *testing.T) {
tfNode := "data.azuredevops_git_repository_file.test"
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()
branch := "refs/heads/master"
file := "foo.txt"
content := "bar"
commitMessage := "first commit"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: hclDataRepositoryFile(projectName, repoName, branch, file, content, commitMessage, file),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "content", content),
resource.TestCheckResourceAttr(tfNode, "last_commit_message", commitMessage),
),
},
},
})
}
func TestAccGitRepositoryFile_DataSource_notExist(t *testing.T) {
projectName := testutils.GenerateResourceName()
repoName := testutils.GenerateResourceName()
branch := "refs/heads/master"
file := "foo.txt"
content := "bar"
commitMessage := "first commit"
not_exists_file := "not_exists.txt"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: hclDataRepositoryFile(projectName, repoName, branch, file, content, commitMessage, not_exists_file),
ExpectError: regexp.MustCompile(fmt.Sprintf("Error: Item not found, repositoryID: [A-Za-z0-9-]+, branch: %s, file: %s", regexp.QuoteMeta(strings.Split(branch, "/")[2]), regexp.QuoteMeta(not_exists_file))),
},
},
})
}
func hclDataRepositoryFile(projectName, repoName, branch, rfile, content, commitMessage, dfile string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
}
resource "azuredevops_git_repository" "test" {
project_id = azuredevops_project.test.id
name = "%[2]s"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_git_repository_file" "test" {
repository_id = azuredevops_git_repository.test.id
branch = "%[3]s"
file = "%[4]s"
content = "%[5]s"
commit_message = "%[6]s"
}
data "azuredevops_git_repository_file" "test" {
repository_id = azuredevops_git_repository.test.id
branch = "%[3]s"
file = "%[7]s"
depends_on = [azuredevops_git_repository_file.test]
}
`, projectName, repoName, branch, rfile, content, commitMessage, dfile)
}