Skip to content

Commit

Permalink
Add integration test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Feb 13, 2022
1 parent 6f125c3 commit 310984f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
8 changes: 8 additions & 0 deletions tests/integration/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

package integration
Expand Down Expand Up @@ -105,3 +106,10 @@ func (s *Executor) Binary(binaryPath string) *Executor {
s.binaryPath = binaryPath
return s
}

func stringDefault(in, def string) string {
if in == "" {
return def
}
return in
}
19 changes: 15 additions & 4 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
)

const (
binaryPathEnvName = "BINARY_PATH"
codeownersSamplesRepo = "https://github.com/gh-codeowners/codeowners-samples.git"
binaryPathEnvName = "BINARY_PATH"
codeownersSamplesRepo = "https://github.com/gh-codeowners/codeowners-samples.git"
caseInsensitiveOrgCodeownersSamplesRepo = "https://github.com/GitHubCODEOWNERS/codeowners-samples.git"
)

// TestCheckHappyPath tests that codeowners-validator reports no issues for valid CODEOWNERS file.
Expand All @@ -31,6 +32,7 @@ func TestCheckSuccess(t *testing.T) {
type Envs map[string]string
tests := []struct {
name string
repo string
envs Envs
skipOS string
}{
Expand All @@ -48,6 +50,15 @@ func TestCheckSuccess(t *testing.T) {
"GITHUB_ACCESS_TOKEN": os.Getenv("GITHUB_TOKEN"),
},
},
{
name: "owners",
envs: Envs{
"CHECKS": "owners",
"OWNER_CHECKER_REPOSITORY": "GitHubCODEOWNERS/codeowners-samples",
"GITHUB_ACCESS_TOKEN": os.Getenv("GITHUB_TOKEN"),
},
repo: caseInsensitiveOrgCodeownersSamplesRepo,
},
{
name: "duppatterns",
envs: Envs{
Expand All @@ -71,7 +82,7 @@ func TestCheckSuccess(t *testing.T) {
}

// given
repoDir, cleanup := CloneRepo(t, codeownersSamplesRepo, "happy-path")
repoDir, cleanup := CloneRepo(t, stringDefault(tc.repo, codeownersSamplesRepo), "happy-path")
defer cleanup()

binaryPath := os.Getenv(binaryPathEnvName)
Expand All @@ -93,7 +104,7 @@ func TestCheckSuccess(t *testing.T) {
normalizedOutput := normalizeTimeDurations(result.Stdout)

g := goldie.New(t, goldie.WithNameSuffix(".golden.txt"))
g.Assert(t, t.Name(), []byte(normalizedOutput))
g.Assert(t, tc.name, []byte(normalizedOutput))
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/testdata/duppatterns.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
==> Executing Duplicated Pattern Checker (<duration>)
Check OK

1 check(s) executed, no failure(s)
4 changes: 4 additions & 0 deletions tests/integration/testdata/files.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
==> Executing File Exist Checker (<duration>)
Check OK

1 check(s) executed, no failure(s)
4 changes: 4 additions & 0 deletions tests/integration/testdata/notowned.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
==> Executing [Experimental] Not Owned File Checker (<duration>)
Check OK

1 check(s) executed, no failure(s)
4 changes: 4 additions & 0 deletions tests/integration/testdata/owners.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
==> Executing Valid Owner Checker (<duration>)
Check OK

1 check(s) executed, no failure(s)

0 comments on commit 310984f

Please sign in to comment.