-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 雑にgoのバージョンをあげておく * newlineの対処 * 関数化 * テストケース追加 * CI追加 * 条件追加 * tidyはformatでやるので必要なし * formatが間違ってたので直してあげたよ! (#252) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * permission設定 * import修正 * stringで比較 * 消されるブロックが最後の場合、一行上の空白行を消す * ロジック修正 * ネストを浅く --------- Co-authored-by: dev-hato-app[bot] <111467236+dev-hato-app[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c9d03e7
commit 80ec7b3
Showing
5 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: test | ||
permissions: | ||
contents: read | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
- name: Set up Go | ||
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | ||
with: | ||
go-version-file: "go.mod" | ||
cache: false | ||
check-latest: true | ||
id: go | ||
- name: go cache restore | ||
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ env.GO-CACHE-VERSION }}-go-cache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}-${{ steps.go.outputs.go-version }}-${{ github.sha }} | ||
restore-keys: | | ||
${{ env.GO-CACHE-VERSION }}-go-cache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}-${{ steps.go.outputs.go-version }}-${{ github.sha }} | ||
${{ env.GO-CACHE-VERSION }}-go-cache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}-${{ steps.go.outputs.go-version }}- | ||
${{ env.GO-CACHE-VERSION }}-go-cache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}- | ||
- name: go test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/hclwrite" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_tfrbac(t *testing.T) { | ||
t.Parallel() | ||
|
||
type args struct { | ||
input []byte | ||
} | ||
tests := map[string]struct { | ||
args args | ||
expected []byte | ||
}{ | ||
"empty": { | ||
args: args{ | ||
input: []byte(""), | ||
}, | ||
expected: nil, | ||
}, | ||
"simple-1-1": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
"simple-1-2": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
"simple-2-1": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
"simple-2-2": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
resource "AAA" "aaa" { | ||
} | ||
`), | ||
}, | ||
"multiple-1": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
moved { | ||
from = "XXX" | ||
to = "YYY" | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
`), | ||
}, | ||
"multiple-2": { | ||
args: args{ | ||
input: []byte( | ||
` | ||
moved { | ||
from = "xxx" | ||
to = "yyy" | ||
} | ||
moved { | ||
from = "XXX" | ||
to = "YYY" | ||
} | ||
`), | ||
}, | ||
expected: []byte( | ||
` | ||
`), | ||
}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
file, diags := hclwrite.ParseConfig(tt.args.input, "", hcl.InitialPos) | ||
if diags.HasErrors() { | ||
require.Fail(t, diags.Error()) | ||
} | ||
actual := tfrbac(file.Body()) | ||
require.Equal(t, string(tt.expected), string(actual.Bytes())) | ||
}) | ||
} | ||
} |