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

Function TestHttpDataSource

datasource/http/data_acc_test.go:30–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28var testDatasourceInvalidMethod string
29
30func TestHttpDataSource(t *testing.T) {
31 tests := []struct {
32 Name string
33 Path string
34 Error bool
35 ExpectedOutputs map[string]string
36 }{
37 {
38 Name: "basic_test",
39 Path: testDatasourceBasic,
40 Error: false,
41 ExpectedOutputs: map[string]string{
42 "url": "url is https://www.google.com",
43 // Check that body is not empty
44 "body": "body is true",
45 },
46 },
47 {
48 Name: "url_is_empty",
49 Path: testDatasourceEmptyUrl,
50 Error: true,
51 ExpectedOutputs: map[string]string{
52 "error": "the `url` must be specified",
53 },
54 },
55 {
56 Name: "method_is_invalid",
57 Path: testDatasourceInvalidMethod,
58 Error: true,
59 ExpectedOutputs: map[string]string{
60 "error": "the `method` must be one of \\[HEAD GET POST PUT DELETE OPTIONS PATCH\\]",
61 },
62 },
63 {
64 Name: "404_url",
65 Path: testDatasource404Url,
66 Error: true,
67 },
68 }
69 for _, tt := range tests {
70 t.Run(tt.Name, func(t *testing.T) {
71 testCase := &acctest.PluginTestCase{
72 Name: tt.Name,
73 Setup: func() error {
74 return nil
75 },
76 Teardown: func() error {
77 return nil
78 },
79 Template: tt.Path,
80 Type: "http",
81 Check: func(buildCommand *exec.Cmd, logfile string) error {
82 if buildCommand.ProcessState != nil {
83 if buildCommand.ProcessState.ExitCode() != 0 && !tt.Error {
84 return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
85 }
86 if tt.Error && buildCommand.ProcessState.ExitCode() == 0 {
87 return fmt.Errorf("Expected Bad exit code.")

Callers

nothing calls this directly

Calls 3

RunMethod · 0.45
ErrorfMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…