Skip to content

Commit 6b173cf

Browse files
authored
Merge pull request #59 from hashicorp/github-actions
move to GitHub Actions
2 parents d88a389 + 14dd994 commit 6b173cf

File tree

5 files changed

+107
-71
lines changed

5 files changed

+107
-71
lines changed

.github/workflows/test.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Tests
2+
on:
3+
pull_request:
4+
branches: [ main ]
5+
paths-ignore:
6+
- 'README.md'
7+
- 'CHANGELOG.md'
8+
- 'website/*'
9+
push:
10+
branches: [ main ]
11+
paths-ignore:
12+
- 'README.md'
13+
- 'CHANGELOG.md'
14+
- 'website/*'
15+
jobs:
16+
build:
17+
name: Build
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
steps:
21+
22+
- name: Set up Go
23+
uses: actions/[email protected]
24+
with:
25+
go-version: '1.16'
26+
id: go
27+
28+
- name: Check out code into the Go module directory
29+
uses: actions/[email protected]
30+
31+
- name: Go fmt
32+
run: |
33+
make fmt
34+
35+
- name: Go vet
36+
run: |
37+
make vet
38+
39+
- name: Build
40+
run: |
41+
go build -v .
42+
43+
44+
# run acceptance tests in a matrix with Terraform core versions
45+
test:
46+
name: Matrix Test
47+
needs: build
48+
runs-on: ${{ matrix.os }}
49+
timeout-minutes: 15
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
os: [macos-latest, windows-latest, ubuntu-latest]
54+
terraform:
55+
- '0.12.31'
56+
- '0.13.7'
57+
- '0.14.11'
58+
- '0.15.5'
59+
- '1.0.1'
60+
steps:
61+
62+
- name: Set up Go
63+
uses: actions/[email protected]
64+
with:
65+
go-version: '1.16'
66+
id: go
67+
68+
- name: Check out code into the Go module directory
69+
uses: actions/[email protected]
70+
71+
- name: TF acceptance tests
72+
timeout-minutes: 10
73+
env:
74+
TF_ACC: "1"
75+
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
76+
run: |
77+
go test -v -cover ./internal/provider/

.travis.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

internal/provider/data_source_local_file_test.go

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,31 @@ import (
1010
)
1111

1212
func TestLocalFileDataSource(t *testing.T) {
13-
var tests = []struct {
14-
content string
15-
config string
16-
}{
17-
{
18-
"This is some content",
19-
`
20-
resource "local_file" "file" {
21-
content = "This is some content"
22-
filename = "local_file"
23-
}
24-
data "local_file" "file" {
25-
filename = "${local_file.file.filename}"
26-
}
27-
`,
28-
},
29-
}
13+
content := "This is some content"
14+
15+
config := `
16+
data "local_file" "file" {
17+
filename = "./testdata/local_file"
18+
}
19+
`
3020

31-
for i, test := range tests {
32-
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
33-
resource.UnitTest(t, resource.TestCase{
34-
Providers: testProviders,
35-
Steps: []resource.TestStep{
36-
{
37-
Config: test.config,
38-
Check: func(s *terraform.State) error {
39-
m := s.RootModule()
40-
i := m.Resources["data.local_file.file"].Primary
41-
if got, want := i.Attributes["content"], test.content; got != want {
42-
return fmt.Errorf("wrong content %q; want %q", got, want)
43-
}
44-
if got, want := i.Attributes["content_base64"], base64.StdEncoding.EncodeToString([]byte(test.content)); got != want {
45-
return fmt.Errorf("wrong content_base64 %q; want %q", got, want)
46-
}
47-
return nil
48-
},
49-
},
21+
resource.UnitTest(t, resource.TestCase{
22+
Providers: testProviders,
23+
Steps: []resource.TestStep{
24+
{
25+
Config: config,
26+
Check: func(s *terraform.State) error {
27+
m := s.RootModule()
28+
i := m.Resources["data.local_file.file"].Primary
29+
if got, want := i.Attributes["content"], content; got != want {
30+
return fmt.Errorf("wrong content %q; want %q", got, want)
31+
}
32+
if got, want := i.Attributes["content_base64"], base64.StdEncoding.EncodeToString([]byte(content)); got != want {
33+
return fmt.Errorf("wrong content_base64 %q; want %q", got, want)
34+
}
35+
return nil
5036
},
51-
})
52-
})
53-
}
37+
},
38+
},
39+
})
5440
}

internal/provider/resource_local_file_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"path/filepath"
1010
"runtime"
11+
"strings"
1112
"testing"
1213

1314
r "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -19,6 +20,7 @@ func TestLocalFile_Basic(t *testing.T) {
1920
defer os.RemoveAll(td)
2021

2122
f := filepath.Join(td, "local_file")
23+
f = strings.ReplaceAll(f, `\`, `\\`)
2224

2325
var cases = []struct {
2426
path string
@@ -140,7 +142,8 @@ func TestLocalFile_Permissions(t *testing.T) {
140142
defer os.RemoveAll(td)
141143

142144
destinationDirPath := td
143-
destinationFilePath := destinationDirPath + "/local_file"
145+
destinationFilePath := filepath.Join(destinationDirPath, "local_file")
146+
destinationFilePath = strings.ReplaceAll(destinationFilePath, `\`, `\\`)
144147
filePermission := os.FileMode(0600)
145148
directoryPermission := os.FileMode(0700)
146149
skipDirCheck := false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is some content

0 commit comments

Comments
 (0)