Skip to content

Commit 15662fc

Browse files
committed
test: Added mutation tests.
1 parent 0e21531 commit 15662fc

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ current_dir := $(dir $(mkfile_path))
1111
# Global stuff.
1212

1313
GO=$(shell which go)
14-
HOMEBREW_PACKAGES=bash bats-core coreutils findutils git git-lfs go jq librsvg nodejs pre-commit python@3.11 tfschema trufflesecurity/trufflehog/trufflehog
14+
HOMEBREW_PACKAGES=bash bats-core coreutils findutils git git-lfs go grep jq librsvg nodejs pre-commit python@3.11 tfschema trufflesecurity/trufflehog/trufflehog
1515

1616
# Determine the operating system and CPU arch.
1717
OS=$(shell uname -o | tr '[:upper:]' '[:lower:]')
@@ -277,7 +277,7 @@ lint: vuln license pre-commit
277277

278278
.PHONY: test
279279
## test: [test]* Runs ALL tests.
280-
test: unit examples acc bats
280+
test: unit examples acc mutate bats
281281

282282
.PHONY: list-tests
283283
## list-tests: [test] Lists all of the tests that are available to run.
@@ -323,17 +323,24 @@ ifeq ($(DEBUG), true)
323323
else
324324
TF_ACC=1 gotestsum --format testname -- -run=TestAcc$(NAME) -count=1 -parallel=$(shell nproc) -timeout 30m -coverpkg=./corefuncprovider/... -coverprofile=__coverage.out -v ./corefuncprovider/...
325325
endif
326-
go-cover-treemap -coverprofile __coverage.out > acc-coverage.svg
327-
rsvg-convert --width=2000 --format=png --output="acc-coverage.png" "acc-coverage.svg"
326+
@ go-cover-treemap -coverprofile __coverage.out > acc-coverage.svg
327+
@ rsvg-convert --width=2000 --format=png --output="acc-coverage.png" "acc-coverage.svg"
328328

329329
.PHONY: unit
330330
## unit: [test] Runs unit tests. Set NAME= (without 'Test') to run a specific test by name
331331
unit:
332332
@ $(ECHO) " "
333333
@ $(ECHO) "\033[1;33m=====> Running unit tests...\033[0m"
334334
gotestsum --format testname -- -run=Test$(NAME) -count=1 -parallel=$(shell nproc) -timeout 30s -coverpkg=./corefunc/... -coverprofile=__coverage.out -v ./corefunc/...
335-
go-cover-treemap -coverprofile __coverage.out > unit-coverage.svg
336-
rsvg-convert --width=2000 --format=png --output="unit-coverage.png" "unit-coverage.svg"
335+
@ go-cover-treemap -coverprofile __coverage.out > unit-coverage.svg
336+
@ rsvg-convert --width=2000 --format=png --output="unit-coverage.png" "unit-coverage.svg"
337+
338+
.PHONY: mutate
339+
## mutate: [test] Runs mutation tests.
340+
mutate:
341+
@ $(ECHO) " "
342+
@ $(ECHO) "\033[1;33m=====> Running mutation tests...\033[0m"
343+
cd ./corefunc && $(GO) test -tags=mutation -count=1 -parallel=$(shell nproc) -timeout 30s -ooze.v=true | ggrep -v "^[[:lower:]]" | ggrep -v "^)"
337344

338345
.PHONY: examples
339346
## examples: [test] Runs tests for examples. Set NAME= (without 'Example') to run a specific test by name
@@ -368,7 +375,7 @@ bench:
368375
pgo:
369376
@ $(ECHO) " "
370377
@ $(ECHO) "\033[1;33m=====> Running benchmark for PGO data...\033[0m"
371-
TF_ACC=1 go test -run=^TestAcc -count=6 -cpuprofile=default.pgo -parallel=$(shell nproc) -timeout 60m ./corefuncprovider/...
378+
TF_ACC=1 go test -run=^TestAcc -count=6 -timeout 60m -cpuprofile=default.pgo -parallel=$(shell nproc) ./corefuncprovider/...
372379

373380
.PHONY: view-cov-cli
374381
## view-cov-cli: [test] After running test or unittest, this will view the coverage report on the CLI.

corefunc/mutation_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2023, Ryan Parman
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build mutation
16+
17+
package corefunc
18+
19+
import (
20+
"testing"
21+
22+
"github.com/gtramontina/ooze"
23+
)
24+
25+
func TestMutation(t *testing.T) {
26+
ooze.Release(
27+
t,
28+
ooze.WithRepositoryRoot("."),
29+
ooze.WithMinimumThreshold(0.75),
30+
ooze.Parallel(),
31+
)
32+
}

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/chanced/caps v1.0.1
77
github.com/google/go-cmp v0.6.0
88
github.com/gookit/color v1.5.4
9+
github.com/gtramontina/ooze v0.2.0
910
github.com/hashicorp/terraform-plugin-docs v0.16.0
1011
github.com/hashicorp/terraform-plugin-framework v1.4.2
1112
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
@@ -50,6 +51,7 @@ require (
5051
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
5152
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5253
github.com/hashicorp/yamux v0.1.1 // indirect
54+
github.com/hexops/gotextdiff v1.0.3 // indirect
5355
github.com/huandu/xstrings v1.4.0 // indirect
5456
github.com/imdario/mergo v0.3.15 // indirect
5557
github.com/inconshreveable/mousetrap v1.1.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
6969
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7070
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
7171
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
72+
github.com/gtramontina/ooze v0.2.0 h1:QDW1zeq1TQgTLbIWuk76GCgNV3adkamYxY1aJNYp/Bc=
73+
github.com/gtramontina/ooze v0.2.0/go.mod h1:e0dltGb+Ws7SQKfoj4XkKf9C/UaIAK2YGWbLKLPwL6k=
7274
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
7375
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
7476
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -119,6 +121,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S
119121
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
120122
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
121123
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
124+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
125+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
122126
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
123127
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
124128
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=

0 commit comments

Comments
 (0)