Skip to content

Commit

Permalink
updates to accept test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
raynaluzier committed Dec 19, 2024
1 parent 973275e commit 21dc32e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ crash.log

dist/*
.docs/*
docs.zip
docs.zip

.env
42 changes: 18 additions & 24 deletions datasource/source_image/data_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,56 +58,50 @@ const testDatasourceHCL2Basic = `
}
`

var artifactUri string
var statusCode string

const testDirName = "test-directory"
const testArtifactName = "test-artifact.txt"
const artifactSuffix = ""
const artifactContents = "Just some test content."

const testRepoName = "test-packer-plugin"
const testRepoConfigName = "repository-config.json"
const repoConfigContents = "{ \"key\": \"" + testRepoName + "\",\"rclass\": \"local\", \"description\": \"temporary; test repo for packer plugin acceptance testing\"}"

var artifactUri string
var statusCode string
var kvProps []string

// Run with: PACKER_ACC=1 go test -count 1 -v ./datasource/source_image/data_acc_test.go -timeout=120
func TestAccDatasource_Artifactory(t *testing.T) {
datasource := Datasource{
config: Config{},
}

// Prep test artifact
testDirPath := common.CreateTestDirectory(testDirName)
testArtifact := common.CreateTestFile(testDirPath, testArtifactName, artifactContents)
var kvProps []string
testArtifactPath := common.CreateTestFile(testDirPath, testArtifactName, artifactContents)
kvProps = append(kvProps,"release=latest-stable")
// Prep Repo Config File
configFilePath := common.CreateTestFile(testDirPath, testRepoConfigName, repoConfigContents)

log.Println("Test Directory Created: " + testDirPath)
log.Println("Test Artifact Created: " + testArtifactPath)

testCase := &acctest.PluginTestCase{
Name: "artifactory_datasource_basic_test",
Setup: func() error {
artifactUri, err := tasks.SetupTest(datasource.config.ArtifactoryServer, datasource.config.AritfactoryToken, testRepoName, configFilePath, testArtifact, artifactSuffix, kvProps)
artifactUri, err := tasks.SetupTest(datasource.config.ArtifactoryServer, datasource.config.AritfactoryToken, testArtifactPath, artifactSuffix, kvProps)
if err != nil {
log.Fatal(err)
}
log.Println("Test Artifact Created: " + artifactUri)
return nil
return nil // move prep back to this function
},
Teardown: func() error {
// Delete local test files
common.DeleteTestFile(configFilePath)
common.DeleteTestFile(testArtifact)

// Delete locat test directory
// Deletes locally created test artifact and test directory
common.DeleteTestFile(testArtifactPath)
common.DeleteTestDirectory(testDirPath)

// Delete test artifact from test repo, then delete test repo
statusCode := tasks.TeardownTest(datasource.config.ArtifactoryServer, datasource.config.AritfactoryToken, testRepoName, artifactUri)
if statusCode == "204" {
fmt.Println("Test environment successfully torn down.")
// Deletes test artifact and repo from Artifactory
statusCode := tasks.TeardownTest(datasource.config.ArtifactoryServer, datasource.config.AritfactoryToken)
if statusCode == "200" {
log.Println("Test environment successfully torn down.")
} else {
fmt.Println("Unable to delete test artifact and/or test repo.")
log.Println("Unable to teardown test environment.")
}
log.Println("Status code of teardown operation: " + statusCode)
return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/packer-plugin-sdk v0.5.4
github.com/raynaluzier/artifactory-go-sdk v1.0.0
github.com/raynaluzier/artifactory-go-sdk v1.0.4
github.com/zclconf/go-cty v1.13.3
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/raynaluzier/artifactory-go-sdk v1.0.0 h1:tuVjw2YVrVZ4+dDhPKnRa5RxK5I4MGzzflR6AMLdaoU=
github.com/raynaluzier/artifactory-go-sdk v1.0.0/go.mod h1:VCpL2xwnMNN7vA4zOD4BeQMQRV6+iAv78q8bSXYcty8=
github.com/raynaluzier/artifactory-go-sdk v1.0.4 h1:TXJpN8ZiTOeTmDUnJ9wPeHUzk62PH9+r5a1VkDYTi78=
github.com/raynaluzier/artifactory-go-sdk v1.0.4/go.mod h1:VCpL2xwnMNN7vA4zOD4BeQMQRV6+iAv78q8bSXYcty8=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
Expand Down

0 comments on commit 21dc32e

Please sign in to comment.