-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate commit sha to avoid common problem (#167)
- Loading branch information
1 parent
438a698
commit 44181f8
Showing
4 changed files
with
86 additions
and
0 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
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,10 @@ | ||
job: | ||
package-manager: go_modules | ||
allowed-updates: | ||
- dependency-type: direct | ||
update-type: all | ||
source: | ||
provider: github | ||
repo: rsc/quote | ||
directory: / | ||
commit: unknown |
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,10 @@ | ||
job: | ||
package-manager: go_modules | ||
allowed-updates: | ||
- dependency-type: direct | ||
update-type: all | ||
source: | ||
provider: github | ||
repo: rsc/quote | ||
directory: / | ||
commit: 5d9f230bcfbae514bb6c2215694c2ce7273fc604 |
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,49 @@ | ||
package tests | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestIntegration(t *testing.T) { | ||
// build the binary for the rest of the tests | ||
_, filename, _, _ := runtime.Caller(0) | ||
testPath := filepath.Dir(filename) | ||
cliMain := path.Join(testPath, "../cmd/dependabot/dependabot.go") | ||
|
||
if data, err := exec.Command("go", "build", cliMain).CombinedOutput(); err != nil { | ||
t.Fatal("Failed to build the binary: ", string(data)) | ||
} | ||
defer func() { | ||
_ = os.Remove("dependabot") | ||
}() | ||
|
||
// Helper to run dependabot in the right directory | ||
dependabot := func(args ...string) (string, error) { | ||
cmd := exec.Command("./dependabot", args...) | ||
cmd.Dir = testPath | ||
output, err := cmd.CombinedOutput() | ||
return string(output), err | ||
} | ||
|
||
t.Run("works with valid commits", func(t *testing.T) { | ||
if output, err := dependabot("update", "-f", "../testdata/valid-commit.yml"); err != nil { | ||
t.Fatal("Expected no error, but got: ", output) | ||
} | ||
}) | ||
|
||
t.Run("rejects invalid commits", func(t *testing.T) { | ||
output, err := dependabot("update", "-f", "../testdata/invalid-commit.yml") | ||
if err == nil { | ||
t.Fatal("Expected an error, but got none") | ||
} | ||
if !strings.Contains(output, "commit must be a SHA, or not provided") { | ||
t.Fatalf("Expected error message to mention bad commit, but got: \n%s", output) | ||
} | ||
}) | ||
} |