github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/formatter_template_test.go (about)

     1  package controldisplay
     2  
     3  //
     4  //type resolveOutputTemplateTestCase struct {
     5  //	input    string // --export <val>
     6  //	expected interface{}
     7  //}
     8  //
     9  //// TODO change this test to GetFormatter and getFormatterByExtension
    10  //
    11  //var resolveOutputTemplateTestCases = map[string]resolveOutputTemplateTestCase{
    12  //	"html": {
    13  //		input: "html",
    14  //		expected: OutputTemplate{
    15  //			FormatFullName: "html.html",
    16  //			FileExtension:  ".html",
    17  //		},
    18  //	},
    19  //	"nunit3": {
    20  //		input: "nunit3",
    21  //		expected: OutputTemplate{
    22  //			FormatFullName: "nunit3.xml",
    23  //			FileExtension:  ".xml",
    24  //		},
    25  //	},
    26  //	"markdown": {
    27  //		input: "md",
    28  //		expected: OutputTemplate{
    29  //			FormatFullName: "md.md",
    30  //			FileExtension:  ".md",
    31  //		},
    32  //	},
    33  //
    34  //	"nunit3.xml": {
    35  //		input: "nunit3.xml",
    36  //		expected: OutputTemplate{
    37  //			FormatFullName: "nunit3.xml",
    38  //			FileExtension:  ".xml",
    39  //		},
    40  //	},
    41  //	"markdown.md": {
    42  //		input:    "markdown.md",
    43  //		expected: "ERROR",
    44  //		//OutputTemplate{
    45  //		//	FormatFullName:  "md.md",
    46  //		//	OutputExtension: ".md",
    47  //		//},
    48  //	},
    49  //	// "txt.dat": {
    50  //	// 	input: "txt.dat",
    51  //	// 	expected: OutputTemplate{
    52  //	// 		FormatFullName:  "txt.dat",
    53  //	// 		OutputExtension: ".dat",
    54  //	// 	},
    55  //	// },
    56  //	// "custom.txt": {
    57  //	// 	input: "custom.txt",
    58  //	// 	expected: OutputTemplate{
    59  //	// 		FormatFullName:  "custom.txt",
    60  //	// 		OutputExtension: ".txt",
    61  //	// 	},
    62  //	// },
    63  //	"foo.xml": {
    64  //		input: "foo.xml",
    65  //
    66  //		expected: "ERROR",
    67  //		//	OutputTemplate{
    68  //		//	FormatFullName:  "nunit3.xml",
    69  //		//	OutputExtension: ".xml",
    70  //		//},
    71  //	},
    72  //	"brief.html": {
    73  //		input:    "brief.html",
    74  //		expected: "ERROR",
    75  //		//	OutputTemplate{
    76  //		//	FormatFullName:  "html.html",
    77  //		//	OutputExtension: ".html",
    78  //		//},
    79  //	},
    80  //	"output.html": {
    81  //		input:    "output.html",
    82  //		expected: "ERROR",
    83  //		//	OutputTemplate{
    84  //		//	FormatFullName:  "html.html",
    85  //		//	OutputExtension: ".html",
    86  //		//},
    87  //	},
    88  //	"output.md": {
    89  //		input:    "output.md",
    90  //		expected: "ERROR",
    91  //		//	OutputTemplate{
    92  //		//	FormatFullName:  "md.md",
    93  //		//	OutputExtension: ".md",
    94  //		//},
    95  //	},
    96  //	// "output.txt": {
    97  //	// 	input: "output.txt",
    98  //	// 	expected: OutputTemplate{
    99  //	// 		FormatFullName:  "custom.txt",
   100  //	// 		OutputExtension: ".txt",
   101  //	// 	},
   102  //	// },
   103  //	// "output.dat": {
   104  //	// 	input: "output.dat",
   105  //	// 	expected: OutputTemplate{
   106  //	// 		FormatFullName:  "txt.dat",
   107  //	// 		OutputExtension: ".dat",
   108  //	// 	},
   109  //	// },
   110  //	"output.brief.html": {
   111  //		input:    "output.brief.html",
   112  //		expected: "ERROR",
   113  //		//	OutputTemplate{
   114  //		//	FormatFullName:  "html.html",
   115  //		//	OutputExtension: ".html",
   116  //		//},
   117  //	},
   118  //	"output.nunit3.xml": {
   119  //		input:    "output.nunit3.xml",
   120  //		expected: "ERROR",
   121  //		//	OutputTemplate{
   122  //		//	FormatFullName:  "nunit3.xml",
   123  //		//	OutputExtension: ".xml",
   124  //		//},
   125  //	},
   126  //	"output.foo.xml": {
   127  //		input:    "output.foo.xml",
   128  //		expected: "ERROR",
   129  //		//	OutputTemplate{
   130  //		//	FormatFullName:  "nunit3.xml",
   131  //		//	OutputExtension: ".xml",
   132  //		//},
   133  //	},
   134  //}
   135  //
   136  //func setup() {
   137  //	filepaths.SteampipeDir = "~/.steampipe"
   138  //	source, err := filepath.Abs("templates")
   139  //	if err != nil {
   140  //		log.Fatal(err)
   141  //	}
   142  //
   143  //	dest, err := filepath.Abs("~/.steampipe/check/templates")
   144  //	if err != nil {
   145  //		log.Fatal(err)
   146  //	}
   147  //
   148  //	err = copy.Copy(source, dest)
   149  //	if err != nil {
   150  //		log.Fatal(err)
   151  //	}
   152  //}
   153  //
   154  //func teardown() {
   155  //	os.RemoveAll("~/.steampipe/check/templates")
   156  //}
   157  //
   158  //func TestResolveOutputTemplate(t *testing.T) {
   159  //	setup()
   160  //	resolver, _ := NewFormatResolver()
   161  //	for name, test := range resolveOutputTemplateTestCases {
   162  //		outputTemplate, err := resolver.resolveOutputTemplate(test.input)
   163  //		if err != nil {
   164  //			if test.expected != "ERROR" {
   165  //				t.Errorf("Test: '%s'' FAILED with unexpected error: %v", name, err)
   166  //			}
   167  //			continue
   168  //		}
   169  //		if test.expected == "ERROR" {
   170  //			t.Errorf("Test: '%s'' FAILED - expected error", name)
   171  //			continue
   172  //		}
   173  //		expectedFormat := test.expected.(OutputTemplate)
   174  //		if !FormatEqual(outputTemplate, &expectedFormat) {
   175  //			t.Errorf("Test: '%s'' FAILED : expected:\n%s\n\ngot:\n%s", name, expectedFormat.FormatName, outputTemplate)
   176  //		}
   177  //	}
   178  //	teardown()
   179  //}
   180  //
   181  //func FormatEqual(l, r *OutputTemplate) bool {
   182  //	return (l.FormatFullName == r.FormatFullName)
   183  //}