@@ -36,9 +36,26 @@ var tableHome = "NAME STATUS SSH CPUS MEMORY DISK DIR
3636var tableAll = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n " +
3737 "foo Stopped 127.0.0.1:0 " + vmtype + " " + goarch + " 0 0B 0B dir\n "
3838
39- var tableTwo = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n " +
40- "foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B dir\n " +
41- "bar Stopped 127.0.0.1:0 vz aarch64 0 0B 0B dir\n "
39+ // for width 60, everything is hidden
40+ var table60 = "NAME STATUS SSH CPUS MEMORY DISK\n " +
41+ "foo Stopped 127.0.0.1:0 0 0B 0B\n "
42+
43+ // for width 80, identical is hidden (type/arch)
44+ var table80i = "NAME STATUS SSH CPUS MEMORY DISK DIR\n " +
45+ "foo Stopped 127.0.0.1:0 0 0B 0B dir\n "
46+
47+ // for width 80, different arch is still shown (not dir)
48+ var table80d = "NAME STATUS SSH ARCH CPUS MEMORY DISK\n " +
49+ "foo Stopped 127.0.0.1:0 unknown 0 0B 0B\n "
50+
51+ // for width 100, nothing is hidden
52+ var table100 = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n " +
53+ "foo Stopped 127.0.0.1:0 qemu " + goarch + " 0 0B 0B dir\n "
54+
55+ // for width 80, directory is hidden (if not identical)
56+ var tableTwo = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK\n " +
57+ "foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B\n " +
58+ "bar Stopped 127.0.0.1:0 vz aarch64 0 0B 0B\n "
4259
4360func TestPrintInstanceTable (t * testing.T ) {
4461 var buf bytes.Buffer
@@ -67,10 +84,44 @@ func TestPrintInstanceTableHome(t *testing.T) {
6784 assert .Equal (t , tableHome , buf .String ())
6885}
6986
87+ func TestPrintInstanceTable60 (t * testing.T ) {
88+ var buf bytes.Buffer
89+ instances := []* Instance {& instance }
90+ options := PrintOptions {TerminalWidth : 60 }
91+ PrintInstances (& buf , instances , "table" , & options )
92+ assert .Equal (t , table60 , buf .String ())
93+ }
94+
95+ func TestPrintInstanceTable80SameArch (t * testing.T ) {
96+ var buf bytes.Buffer
97+ instances := []* Instance {& instance }
98+ options := PrintOptions {TerminalWidth : 80 }
99+ PrintInstances (& buf , instances , "table" , & options )
100+ assert .Equal (t , table80i , buf .String ())
101+ }
102+
103+ func TestPrintInstanceTable80DiffArch (t * testing.T ) {
104+ var buf bytes.Buffer
105+ instance1 := instance
106+ instance1 .Arch = limayaml .NewArch ("unknown" )
107+ instances := []* Instance {& instance1 }
108+ options := PrintOptions {TerminalWidth : 80 }
109+ PrintInstances (& buf , instances , "table" , & options )
110+ assert .Equal (t , table80d , buf .String ())
111+ }
112+
113+ func TestPrintInstanceTable100 (t * testing.T ) {
114+ var buf bytes.Buffer
115+ instances := []* Instance {& instance }
116+ options := PrintOptions {TerminalWidth : 100 }
117+ PrintInstances (& buf , instances , "table" , & options )
118+ assert .Equal (t , table100 , buf .String ())
119+ }
120+
70121func TestPrintInstanceTableAll (t * testing.T ) {
71122 var buf bytes.Buffer
72123 instances := []* Instance {& instance }
73- options := PrintOptions {AllFields : true }
124+ options := PrintOptions {TerminalWidth : 40 , AllFields : true }
74125 PrintInstances (& buf , instances , "table" , & options )
75126 assert .Equal (t , tableAll , buf .String ())
76127}
@@ -86,7 +137,7 @@ func TestPrintInstanceTableTwo(t *testing.T) {
86137 instance2 .VMType = limayaml .VZ
87138 instance2 .Arch = limayaml .AARCH64
88139 instances := []* Instance {& instance1 , & instance2 }
89- options := PrintOptions {}
140+ options := PrintOptions {TerminalWidth : 80 }
90141 PrintInstances (& buf , instances , "table" , & options )
91142 assert .Equal (t , tableTwo , buf .String ())
92143}
0 commit comments