-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2a4404
commit 119051e
Showing
7 changed files
with
389 additions
and
45 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,25 @@ | ||
name: Test processor | ||
|
||
on: | ||
push: | ||
paths: | ||
- "script/**" | ||
|
||
jobs: | ||
test-processor: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: "script/go.mod" | ||
cache-dependency-path: "script/go.sum" | ||
|
||
- name: Install dependencies | ||
run: make install_deps | ||
|
||
- name: Test processor | ||
run: make test |
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,156 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func errNoProjectName(sectionTitle string) error { | ||
return fmt.Errorf("%s: is missing project name", sectionTitle) | ||
} | ||
|
||
func errIncomplete(sectionTitle string) error { | ||
return fmt.Errorf("%s: was not completed for application", sectionTitle) | ||
} | ||
|
||
func errEmpty(sectionTitle string) error { | ||
return fmt.Errorf("%s: is empty", sectionTitle) | ||
} | ||
|
||
func errMustBeChecked(sectionTitle string) error { | ||
return fmt.Errorf("%s: must be checked", sectionTitle) | ||
} | ||
|
||
func errInvalidAccountUrl(sectionTitle string) error { | ||
return fmt.Errorf("%s: is invalid 1Password account URL", sectionTitle) | ||
} | ||
|
||
func errContainsEmoji(sectionTitle string) error { | ||
return fmt.Errorf("%s: cannot contain emoji characters", sectionTitle) | ||
} | ||
|
||
func errParsingNumber(sectionTitle string) error { | ||
return fmt.Errorf("%s: could not be parsed into a number", sectionTitle) | ||
} | ||
|
||
func errInvalidUrl(sectionTitle string) error { | ||
return fmt.Errorf("%s: is an invalid URL", sectionTitle) | ||
} | ||
|
||
func TestApplication(t *testing.T) { | ||
originalDir, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("Failed to get current directory: %s", err) | ||
} | ||
|
||
defer func() { | ||
if err := os.Chdir(originalDir); err != nil { | ||
t.Fatalf("Failed to change back to original directory: %s", err) | ||
} | ||
}() | ||
|
||
if err := os.Chdir("../"); err != nil { | ||
t.Fatalf("Failed to change working directory: %s", err) | ||
} | ||
|
||
testCases := []struct { | ||
name string | ||
expectedValid bool | ||
expectedProblems []error | ||
}{ | ||
{ | ||
name: "project", | ||
expectedValid: true, | ||
}, | ||
{ | ||
name: "team", | ||
expectedValid: true, | ||
}, | ||
{ | ||
name: "event", | ||
expectedValid: true, | ||
}, | ||
{ | ||
name: "empty-body", | ||
expectedValid: false, | ||
expectedProblems: []error{ | ||
errIncomplete("Account URL"), | ||
errIncomplete("Non-commercial confirmation"), | ||
errIncomplete("Team application"), | ||
errIncomplete("Event application"), | ||
errIncomplete("Project name"), | ||
errIncomplete("Short description"), | ||
errIncomplete("Number of team members/core contributors"), | ||
errIncomplete("Homepage URL"), | ||
errIncomplete("Repository URL"), | ||
errIncomplete("License type"), | ||
errIncomplete("License URL"), | ||
errIncomplete("Age confirmation"), | ||
errIncomplete("Name"), | ||
errIncomplete("Email"), | ||
errIncomplete("Project role"), | ||
errIncomplete("Profile or website"), | ||
errIncomplete("Additional comments"), | ||
errIncomplete("Can we contact you?"), | ||
}, | ||
}, | ||
{ | ||
name: "no-responses", | ||
expectedValid: false, | ||
expectedProblems: []error{ | ||
errNoProjectName("Application title"), | ||
errEmpty("Account URL"), | ||
errMustBeChecked("Non-commercial confirmation"), | ||
errEmpty("Project name"), | ||
errEmpty("Short description"), | ||
errEmpty("Number of team members/core contributors"), | ||
errEmpty("Homepage URL"), | ||
errEmpty("License type"), | ||
errEmpty("License URL"), | ||
errMustBeChecked("Age confirmation"), | ||
errEmpty("Name"), | ||
errEmpty("Email"), | ||
errEmpty("Project role"), | ||
}, | ||
}, | ||
{ | ||
name: "examples-1", | ||
expectedValid: false, | ||
expectedProblems: []error{ | ||
errNoProjectName("Application title"), | ||
errInvalidAccountUrl("Account URL"), | ||
errMustBeChecked("Non-commercial confirmation"), | ||
errContainsEmoji("Project name"), | ||
errParsingNumber("Number of team members/core contributors"), | ||
errInvalidUrl("Homepage URL"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range testCases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
application := Application{} | ||
|
||
if tt.expectedValid { | ||
testIssueName = fmt.Sprintf("valid-%s", tt.name) | ||
} else { | ||
testIssueName = fmt.Sprintf("invalid-%s", tt.name) | ||
} | ||
|
||
application.Parse(*getTestIssue()) | ||
|
||
if application.IsValid() != tt.expectedValid { | ||
if tt.expectedValid { | ||
t.Errorf("Test issue '%s' is invalid, expected valid", testIssueName) | ||
} else { | ||
t.Errorf("Test issue '%s' is valid, expected invalid", testIssueName) | ||
} | ||
} | ||
|
||
if !tt.expectedValid && !errSliceEqual(application.Problems, tt.expectedProblems) { | ||
t.Errorf("Expected problems %v, got %v", tt.expectedProblems, application.Problems) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.