MCPcopy
hub / github.com/spf13/viper / TestWriteConfig

Function TestWriteConfig

viper_test.go:1765–1841  ·  view source on GitHub ↗

var yamlWriteExpected = []byte(`age: 35 beard: true clothing: jacket: leather pants: size: large trousers: denim eyes: brown hacker: true hobbies: - skateboarding - snowboarding - go name: steve `)

(t *testing.T)

Source from the content-addressed store, hash-verified

1763// `)
1764
1765func TestWriteConfig(t *testing.T) {
1766 fs := afero.NewMemMapFs()
1767 testCases := map[string]struct {
1768 configName string
1769 inConfigType string
1770 outConfigType string
1771 fileName string
1772 input []byte
1773 expectedContent []byte
1774 }{
1775 "json with file extension": {
1776 configName: "c",
1777 inConfigType: "json",
1778 outConfigType: "json",
1779 fileName: "c.json",
1780 input: jsonExample,
1781 expectedContent: jsonWriteExpected,
1782 },
1783 "json without file extension": {
1784 configName: "c",
1785 inConfigType: "json",
1786 outConfigType: "json",
1787 fileName: "c",
1788 input: jsonExample,
1789 expectedContent: jsonWriteExpected,
1790 },
1791 "json with file extension and mismatch type": {
1792 configName: "c",
1793 inConfigType: "json",
1794 outConfigType: "hcl",
1795 fileName: "c.json",
1796 input: jsonExample,
1797 expectedContent: jsonWriteExpected,
1798 },
1799 "yaml with file extension": {
1800 configName: "c",
1801 inConfigType: "yaml",
1802 outConfigType: "yaml",
1803 fileName: "c.yaml",
1804 input: yamlExample,
1805 expectedContent: yamlWriteExpected,
1806 },
1807 "yaml without file extension": {
1808 configName: "c",
1809 inConfigType: "yaml",
1810 outConfigType: "yaml",
1811 fileName: "c",
1812 input: yamlExample,
1813 expectedContent: yamlWriteExpected,
1814 },
1815 "yaml with file extension and mismatch type": {
1816 configName: "c",
1817 inConfigType: "yaml",
1818 outConfigType: "json",
1819 fileName: "c.yaml",
1820 input: yamlExample,
1821 expectedContent: yamlWriteExpected,
1822 },

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
SetFsMethod · 0.80
SetConfigNameMethod · 0.80
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
WriteConfigAsMethod · 0.80

Tested by

no test coverage detected