-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: run acceptance tests from github workflow
- Loading branch information
Showing
3 changed files
with
108 additions
and
3 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,4 @@ | ||
.PHONY: test-acc | ||
test-acc: | ||
TF_ACC=1 \ | ||
go test ./... -v -run=^TestAcc_ -count=1 -coverprofile=cov.out -coverpkg "github.com/ctfer-io/terraform-provider-ctfd/internal/provider,github.com/ctfer-io/terraform-provider-ctfd/internal/provider/challenge,github.com/ctfer-io/terraform-provider-ctfd/internal/provider/utils,github.com/ctfer-io/terraform-provider-ctfd/internal/provider/validators" |
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/ctfer-io/go-ctfd/api" | ||
) | ||
|
||
// This utility setup a brand new CTFd instance for acceptance testing of the provider, | ||
// and creates an API key ready to work. | ||
|
||
func main() { | ||
url := os.Getenv("CTFD_URL") | ||
|
||
// Note: add /setup so won't have to follow redirect | ||
fmt.Println("[+] Getting initial nonce and session values") | ||
nonce, session, err := api.GetNonceAndSession(url) | ||
if err != nil { | ||
log.Fatalf("Getting nonce and session: %s", err) | ||
} | ||
|
||
// Setup CTFd | ||
fmt.Println("[+] Setting up CTFd") | ||
client := api.NewClient(url, nonce, session, "") | ||
if err := client.Setup(&api.SetupParams{ | ||
CTFName: "TFP-CTFd", | ||
CTFDescription: "Terraform Provider CTFd.", | ||
UserMode: "users", | ||
Name: "ctfer", | ||
Email: "[email protected]", | ||
Password: "ctfer", | ||
ChallengeVisibility: "public", | ||
AccountVisibility: "public", | ||
ScoreVisibility: "public", | ||
RegistrationVisibility: "public", | ||
VerifyEmails: false, | ||
TeamSize: nil, | ||
CTFLogo: nil, | ||
CTFBanner: nil, | ||
CTFSmallIcon: nil, | ||
CTFTheme: "core", | ||
ThemeColor: "", | ||
Start: "", | ||
End: "", | ||
Nonce: nonce, | ||
}); err != nil { | ||
log.Fatalf("Setting up CTFd: %s", err) | ||
} | ||
|
||
// Create API Key | ||
fmt.Println("[+] Creating API Token") | ||
token, err := client.PostTokens(&api.PostTokensParams{ | ||
Expiration: "2222-01-01", | ||
Description: "Github Workflow CI API token.", | ||
}) | ||
if err != nil { | ||
log.Fatalf("Creating API token: %s", err) | ||
} | ||
|
||
ghf := os.Getenv("GITHUB_ENV") | ||
f, err := os.OpenFile(ghf, os.O_WRONLY|os.O_APPEND, 0644) | ||
if err != nil { | ||
log.Fatalf("Opening $GITHUB_ENV file (%s): %s", ghf, err) | ||
} | ||
defer f.Close() | ||
if _, err := f.WriteString(fmt.Sprintf("CTFD_API_KEY=%s\n", *token.Value)); err != nil { | ||
log.Fatalf("Writing CTFD_API_KEY to $GITHUB_ENV file (%s): %s", ghf, err) | ||
} | ||
} |