github.com/openshift/installer@v1.4.17/pkg/asset/logging/filelogging_test.go (about) 1 package logging 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/openshift/installer/pkg/asset" 9 "github.com/openshift/installer/pkg/asset/installconfig" 10 "github.com/openshift/installer/pkg/asset/machines" 11 ) 12 13 func getAsset(filename string) *asset.File { 14 return &asset.File{ 15 Filename: filename, 16 } 17 } 18 19 func TestLogFilesChanged(t *testing.T) { 20 cases := []struct { 21 name string 22 assets []asset.WritableAsset 23 cmdName string 24 directory string 25 expectedGenerationLog string 26 }{ 27 { 28 name: "test empty assets list", 29 assets: []asset.WritableAsset{}, 30 cmdName: "test", 31 directory: "test", 32 expectedGenerationLog: "", 33 }, 34 { 35 name: "test asset with one file", 36 assets: []asset.WritableAsset{ 37 &installconfig.InstallConfig{ 38 AssetBase: installconfig.AssetBase{ 39 File: &asset.File{ 40 Filename: "a.yaml", 41 }, 42 }, 43 }, 44 }, 45 cmdName: "test install config", 46 directory: "test/", 47 expectedGenerationLog: "Test Install Config created in: test", 48 }, 49 { 50 name: "test asset with two files, same directory", 51 assets: []asset.WritableAsset{ 52 &machines.Master{ 53 MachineFiles: []*asset.File{ 54 getAsset("a.yaml"), 55 getAsset("b.yaml"), 56 }, 57 }, 58 }, 59 cmdName: "machines", 60 directory: "test", 61 expectedGenerationLog: "Machines created in: test", 62 }, 63 { 64 name: "test asset with two files, two directories", 65 assets: []asset.WritableAsset{ 66 &machines.Master{ 67 MachineFiles: []*asset.File{ 68 getAsset("a.yaml"), 69 getAsset("machines/b.yaml"), 70 }, 71 }, 72 }, 73 cmdName: "machines", 74 directory: "test", 75 expectedGenerationLog: "Machines created in: test and test/machines", 76 }, 77 { 78 name: "test asset with two files, two directories, but three entries (same file twice", 79 assets: []asset.WritableAsset{ 80 &machines.Master{ 81 MachineFiles: []*asset.File{ 82 getAsset("a.yaml"), 83 getAsset("machines/b.yaml"), 84 getAsset("machines/b.yaml"), 85 }, 86 }, 87 }, 88 cmdName: "machines", 89 directory: "test", 90 expectedGenerationLog: "Machines created in: test and test/machines", 91 }, 92 { 93 name: "test asset with three files, two directories", 94 assets: []asset.WritableAsset{ 95 &machines.Master{ 96 MachineFiles: []*asset.File{ 97 getAsset("a.yaml"), 98 getAsset("machines/b.yaml"), 99 getAsset("machines/c.yaml"), 100 }, 101 }, 102 }, 103 cmdName: "machine-config", 104 directory: "test/", 105 expectedGenerationLog: "Machine-Config created in: test and test/machines", 106 }, 107 { 108 name: "test asset with three files, three directories", 109 assets: []asset.WritableAsset{ 110 &machines.Master{ 111 MachineFiles: []*asset.File{ 112 getAsset("a.yaml"), 113 getAsset("machines/b.yaml"), 114 getAsset("control-plane/c.yaml"), 115 }, 116 }, 117 }, 118 cmdName: "machines", 119 directory: "test", 120 expectedGenerationLog: "Machines created in: test, test/control-plane and test/machines", 121 }, 122 { 123 name: "test asset with five files, five directories", 124 assets: []asset.WritableAsset{ 125 &machines.Master{ 126 MachineFiles: []*asset.File{ 127 getAsset("a.yaml"), 128 getAsset("machines/b.yaml"), 129 getAsset("control-plane/c.yaml"), 130 getAsset("master/c.yaml"), 131 getAsset("worker/c.yaml"), 132 }, 133 }, 134 }, 135 cmdName: "machines", 136 directory: "test", 137 expectedGenerationLog: "Machines created in: test", 138 }, 139 { 140 name: "test asset with five files, five nested directories", 141 assets: []asset.WritableAsset{ 142 &machines.Master{ 143 MachineFiles: []*asset.File{ 144 getAsset("machines/workers/b.yaml"), 145 getAsset("control-plane/disks/c.yaml"), 146 getAsset("control-plane/VM/d.yaml"), 147 getAsset("machines/configurations/c.yaml"), 148 }, 149 }, 150 }, 151 cmdName: "machines", 152 directory: "test", 153 expectedGenerationLog: "Machines created in: test/control-plane and test/machines", 154 }, 155 } 156 157 for _, tc := range cases { 158 t.Run(tc.name, func(t *testing.T) { 159 textOutput := LogCreatedFiles(tc.cmdName, tc.directory, tc.assets) 160 assert.EqualValues(t, tc.expectedGenerationLog, textOutput) 161 }) 162 163 } 164 }