MCPcopy
hub / github.com/hashicorp/packer / TestDetectFilename

Function TestDetectFilename

post-processor/compress/post-processor_test.go:24–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestDetectFilename(t *testing.T) {
25 // Test default / fallback with no file extension
26 nakedFilename := Config{OutputPath: "test"}
27 nakedFilename.detectFromFilename()
28 if nakedFilename.Archive != "tar" {
29 t.Error("Expected to find tar archive setting")
30 }
31 if nakedFilename.Algorithm != "pgzip" {
32 t.Error("Expected to find pgzip algorithm setting")
33 }
34
35 // Test .archive
36 zipFilename := Config{OutputPath: "test.zip"}
37 zipFilename.detectFromFilename()
38 if zipFilename.Archive != "zip" {
39 t.Error("Expected to find zip archive setting")
40 }
41 if zipFilename.Algorithm != "" {
42 t.Error("Expected to find empty algorithm setting")
43 }
44
45 // Test .compress
46 lz4Filename := Config{OutputPath: "test.lz4"}
47 lz4Filename.detectFromFilename()
48 if lz4Filename.Archive != "" {
49 t.Error("Expected to find empty archive setting")
50 }
51 if lz4Filename.Algorithm != "lz4" {
52 t.Error("Expected to find lz4 algorithm setting")
53 }
54
55 // Test .archive.compress with some.extra.dots...
56 lotsOfDots := Config{OutputPath: "test.blah.bloo.blee.tar.lz4"}
57 lotsOfDots.detectFromFilename()
58 if lotsOfDots.Archive != "tar" {
59 t.Error("Expected to find tar archive setting")
60 }
61 if lotsOfDots.Algorithm != "lz4" {
62 t.Error("Expected to find lz4 algorithm setting")
63 }
64}
65
66const expectedFileContents = "Hello world!"
67

Callers

nothing calls this directly

Calls 2

detectFromFilenameMethod · 0.95
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…