| 
 | 1 | +package test  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"context"  | 
 | 5 | +	"fmt"  | 
 | 6 | +	"os"  | 
 | 7 | +	// "strconv"  | 
 | 8 | +	"testing"  | 
 | 9 | +	"strings"  | 
 | 10 | + | 
 | 11 | +	helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper"  | 
 | 12 | +	awsTerratest "github.com/gruntwork-io/terratest/modules/aws"  | 
 | 13 | +	"github.com/gruntwork-io/terratest/modules/random"  | 
 | 14 | +	"github.com/google/go-github/v70/github"  | 
 | 15 | +	"github.com/stretchr/testify/assert"  | 
 | 16 | +)  | 
 | 17 | + | 
 | 18 | +type ComponentSuite struct {  | 
 | 19 | +	helper.TestSuite  | 
 | 20 | +}  | 
 | 21 | + | 
 | 22 | +func (s *ComponentSuite) TestBasic() {  | 
 | 23 | +	const component = "argocd-github-repo/basic"  | 
 | 24 | +	const stack = "default-test"  | 
 | 25 | +	const awsRegion = "us-east-2"  | 
 | 26 | +	const githubOrg = "cloudposse-tests"  | 
 | 27 | + | 
 | 28 | +	token := os.Getenv("GITHUB_TOKEN")  | 
 | 29 | + | 
 | 30 | +	randomID := strings.ToLower(random.UniqueId())  | 
 | 31 | + | 
 | 32 | +	secretPath := fmt.Sprintf("/argocd/%s/github/api_key", randomID)  | 
 | 33 | +	deployKeyPath := fmt.Sprintf("/argocd/deploy_keys/%s/%s", randomID, "%s")  | 
 | 34 | +	repoName := fmt.Sprintf("argocd-github-repo-%s", randomID)  | 
 | 35 | + | 
 | 36 | +	defer func() {  | 
 | 37 | +		awsTerratest.DeleteParameter(s.T(), awsRegion, secretPath)  | 
 | 38 | +	}()  | 
 | 39 | +	awsTerratest.PutParameter(s.T(), awsRegion, secretPath, "Github API Key", token)  | 
 | 40 | + | 
 | 41 | +	inputs := map[string]interface{}{  | 
 | 42 | +		"ssm_github_deploy_key_format": deployKeyPath,  | 
 | 43 | +		"ssm_github_api_key": secretPath,  | 
 | 44 | +		"name": repoName,  | 
 | 45 | +		"github_organization": githubOrg,  | 
 | 46 | +	}  | 
 | 47 | + | 
 | 48 | +	defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs)  | 
 | 49 | +	options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs)  | 
 | 50 | +	assert.NotNil(s.T(), options)  | 
 | 51 | + | 
 | 52 | +	client := github.NewClient(nil).WithAuthToken(token)  | 
 | 53 | + | 
 | 54 | +	// Check if the repository exists  | 
 | 55 | +	repo, _, err := client.Repositories.Get(context.Background(), githubOrg, repoName)  | 
 | 56 | +	assert.Nil(s.T(), err)  | 
 | 57 | +	assert.NotNil(s.T(), repo)  | 
 | 58 | + | 
 | 59 | +	filePath := "mgmt/uw2-sandbox/argocd/applicationset.yaml"  | 
 | 60 | +	// Use the GitHub API to check if the file exists in the repository  | 
 | 61 | +	_, _, _, err = client.Repositories.GetContents(context.Background(), githubOrg, repoName, filePath, nil)  | 
 | 62 | +	assert.Nil(s.T(), err)  | 
 | 63 | +	s.DriftTest(component, stack, &inputs)  | 
 | 64 | +}  | 
 | 65 | + | 
 | 66 | +func (s *ComponentSuite) TestEnabledFlag() {  | 
 | 67 | +	const component = "argocd-github-repo/disabled"  | 
 | 68 | +	const stack = "default-test"  | 
 | 69 | +	const awsRegion = "us-east-2"  | 
 | 70 | + | 
 | 71 | +	s.VerifyEnabledFlag(component, stack, nil)  | 
 | 72 | +}  | 
 | 73 | + | 
 | 74 | +func TestRunSuite(t *testing.T) {  | 
 | 75 | +	suite := new(ComponentSuite)  | 
 | 76 | +	helper.Run(t, suite)  | 
 | 77 | +}  | 
0 commit comments