@@ -1637,3 +1637,267 @@ func TestTranslateGrub(t *testing.T) {
1637
1637
})
1638
1638
}
1639
1639
}
1640
+
1641
+ func TestTranslateSelinux (t * testing.T ) {
1642
+ translations := []translate.Translation {
1643
+ {From : path .New ("yaml" , "version" ), To : path .New ("json" , "ignition" , "version" )},
1644
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" )},
1645
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" )},
1646
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 )},
1647
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "path" )},
1648
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "device" )},
1649
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "format" )},
1650
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" )},
1651
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 )},
1652
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1653
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1654
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1655
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1656
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1657
+ }
1658
+ tests := []struct {
1659
+ in Config
1660
+ out types.Config
1661
+ exceptions []translate.Translation
1662
+ report report.Report
1663
+ }{
1664
+ // config with one module
1665
+ {
1666
+ Config {
1667
+ Selinux : Selinux {
1668
+ Module : []Module {
1669
+ {
1670
+ Name : "some_name" ,
1671
+ Content : "some content here" ,
1672
+ },
1673
+ },
1674
+ },
1675
+ },
1676
+ types.Config {
1677
+ Ignition : types.Ignition {
1678
+ Version : "3.5.0-experimental" ,
1679
+ },
1680
+ Storage : types.Storage {
1681
+ Filesystems : []types.Filesystem {
1682
+ {
1683
+ Device : "/dev/disk/by-label/boot" ,
1684
+ Format : util .StrToPtr ("ext4" ),
1685
+ Path : util .StrToPtr ("/boot" ),
1686
+ },
1687
+ },
1688
+ Files : []types.File {
1689
+ {
1690
+ Node : types.Node {
1691
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1692
+ },
1693
+ FileEmbedded1 : types.FileEmbedded1 {
1694
+ Append : []types.Resource {
1695
+ {
1696
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1697
+ Compression : util .StrToPtr ("" ),
1698
+ },
1699
+ },
1700
+ },
1701
+ },
1702
+ },
1703
+ },
1704
+ },
1705
+ translations ,
1706
+ report.Report {},
1707
+ },
1708
+ }
1709
+
1710
+ for i , test := range tests {
1711
+ t .Run (fmt .Sprintf ("translate %d" , i ), func (t * testing.T ) {
1712
+ actual , translations , r := test .in .ToIgn3_5Unvalidated (common.TranslateOptions {})
1713
+ r = confutil .TranslateReportPaths (r , translations )
1714
+ baseutil .VerifyReport (t , test .in , r )
1715
+ assert .Equal (t , test .out , actual , "translation mismatch" )
1716
+ assert .Equal (t , test .report , r , "report mismatch" )
1717
+ baseutil .VerifyTranslations (t , translations , test .exceptions )
1718
+ assert .NoError (t , translations .DebugVerifyCoverage (actual ), "incomplete TranslationSet coverage" )
1719
+ })
1720
+ }
1721
+ }
1722
+
1723
+ func TestTranslateSelinuxaaa (t * testing.T ) {
1724
+ translations := []translate.Translation {
1725
+ {From : path .New ("yaml" , "version" ), To : path .New ("json" , "ignition" , "version" )},
1726
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" )},
1727
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" )},
1728
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 )},
1729
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "path" )},
1730
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "device" )},
1731
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "format" )},
1732
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" )},
1733
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 )},
1734
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1735
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1736
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1737
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1738
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1739
+ }
1740
+
1741
+ // With one module
1742
+ in := Config {
1743
+ Selinux : Selinux {
1744
+ Module : []Module {
1745
+ {
1746
+ Name : "some_name" ,
1747
+ Content : "some content here" ,
1748
+ },
1749
+ },
1750
+ },
1751
+ }
1752
+ out := types.Config {
1753
+ Ignition : types.Ignition {
1754
+ Version : "3.5.0-experimental" ,
1755
+ },
1756
+ Storage : types.Storage {
1757
+ Filesystems : []types.Filesystem {
1758
+ {
1759
+ Device : "/dev/disk/by-label/boot" ,
1760
+ Format : util .StrToPtr ("ext4" ),
1761
+ Path : util .StrToPtr ("/boot" ),
1762
+ },
1763
+ },
1764
+ Files : []types.File {
1765
+ {
1766
+ Node : types.Node {
1767
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1768
+ },
1769
+ FileEmbedded1 : types.FileEmbedded1 {
1770
+ Append : []types.Resource {
1771
+ {
1772
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1773
+ Compression : util .StrToPtr ("" ),
1774
+ },
1775
+ },
1776
+ },
1777
+ },
1778
+ },
1779
+ },
1780
+ }
1781
+
1782
+ test := struct {
1783
+ in Config
1784
+ out types.Config
1785
+ exceptions []translate.Translation
1786
+ report report.Report
1787
+ }{
1788
+ in ,
1789
+ out ,
1790
+ translations ,
1791
+ report.Report {},
1792
+ }
1793
+
1794
+ t .Run (fmt .Sprintf ("translate %d" , 0 ), func (t * testing.T ) {
1795
+ actual , translations , r := test .in .ToIgn3_5Unvalidated (common.TranslateOptions {})
1796
+ r = confutil .TranslateReportPaths (r , translations )
1797
+ baseutil .VerifyReport (t , test .in , r )
1798
+ assert .Equal (t , test .out , actual , "translation mismatch" )
1799
+ assert .Equal (t , test .report , r , "report mismatch" )
1800
+ baseutil .VerifyTranslations (t , translations , test .exceptions )
1801
+ assert .NoError (t , translations .DebugVerifyCoverage (actual ), "incomplete TranslationSet coverage" )
1802
+ })
1803
+ }
1804
+
1805
+ // TODO: testing with two modules and merge those two tests and other scenerios
1806
+ func TestTranslateModule (t * testing.T ) {
1807
+ translations := []translate.Translation {
1808
+ {From : path .New ("yaml" , "version" ), To : path .New ("json" , "ignition" , "version" )},
1809
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" )},
1810
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" )},
1811
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 )},
1812
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "path" )},
1813
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "device" )},
1814
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "format" )},
1815
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" )},
1816
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 )},
1817
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1818
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1819
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1820
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1821
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1822
+ }
1823
+
1824
+ // With 2 modules
1825
+ in := Config {
1826
+ Selinux : Selinux {
1827
+ Module : []Module {
1828
+ {
1829
+ Name : "some_name" ,
1830
+ Content : "some content here" ,
1831
+ },
1832
+ {
1833
+ Name : "another_name" ,
1834
+ Content : "some content here" ,
1835
+ },
1836
+ },
1837
+ },
1838
+ }
1839
+ out := types.Config {
1840
+ Ignition : types.Ignition {
1841
+ Version : "3.5.0-experimental" ,
1842
+ },
1843
+ Storage : types.Storage {
1844
+ Filesystems : []types.Filesystem {
1845
+ {
1846
+ Device : "/dev/disk/by-label/boot" ,
1847
+ Format : util .StrToPtr ("ext4" ),
1848
+ Path : util .StrToPtr ("/boot" ),
1849
+ },
1850
+ },
1851
+ Files : []types.File {
1852
+ {
1853
+ Node : types.Node {
1854
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1855
+ },
1856
+ FileEmbedded1 : types.FileEmbedded1 {
1857
+ Append : []types.Resource {
1858
+ {
1859
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1860
+ Compression : util .StrToPtr ("" ),
1861
+ },
1862
+ },
1863
+ },
1864
+ },
1865
+ {
1866
+ Node : types.Node {
1867
+ Path : "/etc/selinux/targeted/modules/active/extra/another_name.cil" ,
1868
+ },
1869
+ FileEmbedded1 : types.FileEmbedded1 {
1870
+ Append : []types.Resource {
1871
+ {
1872
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1873
+ Compression : util .StrToPtr ("" ),
1874
+ },
1875
+ },
1876
+ },
1877
+ },
1878
+ },
1879
+ },
1880
+ }
1881
+
1882
+ test := struct {
1883
+ in Config
1884
+ out types.Config
1885
+ exceptions []translate.Translation
1886
+ report report.Report
1887
+ }{
1888
+ in ,
1889
+ out ,
1890
+ translations ,
1891
+ report.Report {},
1892
+ }
1893
+
1894
+ t .Run (fmt .Sprintf ("translate %d" , 0 ), func (t * testing.T ) {
1895
+ actual , translations , r := test .in .ToIgn3_5Unvalidated (common.TranslateOptions {})
1896
+ r = confutil .TranslateReportPaths (r , translations )
1897
+ baseutil .VerifyReport (t , test .in , r )
1898
+ assert .Equal (t , test .out , actual , "translation mismatch" )
1899
+ assert .Equal (t , test .report , r , "report mismatch" )
1900
+ baseutil .VerifyTranslations (t , translations , test .exceptions )
1901
+ assert .NoError (t , translations .DebugVerifyCoverage (actual ), "incomplete TranslationSet coverage" )
1902
+ })
1903
+ }
0 commit comments