Files
Packer-Cn/datasource/hcp-packer-iteration/data_acc_test.go
hashicorp-copywrite[bot] 19055df3ec [COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00

54 lines
1.7 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package hcp_packer_iteration
import (
_ "embed"
"fmt"
"os"
"os/exec"
"testing"
"github.com/hashicorp/packer-plugin-sdk/acctest"
"github.com/hashicorp/packer/internal/hcp/env"
)
//go:embed test-fixtures/template.pkr.hcl
var testDatasourceBasic string
// Acceptance tests for data sources.
//
// To be successful, the HCP project you're providing credentials for must
// contain a bucket named "hardened-ubuntu-16-04", with a channel named
// "packer-acc-test". It must contain a build that references an image in AWS
// region "us-east-1". Your HCP credentials must be provided through your
// runtime environment because the template this test uses does not set them.
//
// TODO: update this acceptance to create and clean up the HCP resources this
// data source queries, to prevent plugin developers from having to have images
// as defined above.
func TestAccDatasource_HCPPackerIteration(t *testing.T) {
if os.Getenv(env.HCPClientID) == "" && os.Getenv(env.HCPClientSecret) == "" {
t.Skipf(fmt.Sprintf("Acceptance tests skipped unless envs %q and %q are set", env.HCPClientID, env.HCPClientSecret))
return
}
testCase := &acctest.PluginTestCase{
Name: "hcp_packer_iteration_datasource_basic_test",
Template: testDatasourceBasic,
// TODO have acc test write iteration id to a file and check it to make
// sure it isn't empty.
Check: func(buildCommand *exec.Cmd, logfile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
}
}
return nil
},
}
acctest.TestPlugin(t, testCase)
}