Skip to content

Commit 6ad1e59

Browse files
provider/archive: Test that archive_file hashes seem plausible
We just check these for syntax rather than exact value because the underlying archive library is free to evolve its exact encoding over time as long as the result is semantically equivalent, and we don't want these tests to break when we build on different versions of Go.
1 parent ea93b91 commit 6ad1e59

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

builtin/providers/archive/data_source_archive_file_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package archive
33
import (
44
"fmt"
55
"os"
6+
"regexp"
67
"testing"
78

89
r "github.com/hashicorp/terraform/helper/resource"
@@ -19,6 +20,21 @@ func TestAccArchiveFile_Basic(t *testing.T) {
1920
Check: r.ComposeTestCheckFunc(
2021
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
2122
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
23+
24+
// We just check the hashes for syntax rather than exact
25+
// content since we don't want to break if the archive
26+
// library starts generating different bytes that are
27+
// functionally equivalent.
28+
r.TestMatchResourceAttr(
29+
"data.archive_file.foo", "output_base64sha256",
30+
regexp.MustCompile(`^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$`),
31+
),
32+
r.TestMatchResourceAttr(
33+
"data.archive_file.foo", "output_md5", regexp.MustCompile(`^[0-9a-f]{32}$`),
34+
),
35+
r.TestMatchResourceAttr(
36+
"data.archive_file.foo", "output_sha", regexp.MustCompile(`^[0-9a-f]{40}$`),
37+
),
2238
),
2339
},
2440
r.TestStep{

0 commit comments

Comments
 (0)