|
| 1 | +/* |
| 2 | + Copyright The KWasm Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package shim //nolint:testpackage // whitebox test |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/spf13/afero" |
| 23 | + tests "github.com/spinkube/runtime-class-manager/tests/node-installer" |
| 24 | +) |
| 25 | + |
| 26 | +func TestConfig_Uninstall(t *testing.T) { |
| 27 | + type fields struct { |
| 28 | + hostFs afero.Fs |
| 29 | + kwasmPath string |
| 30 | + } |
| 31 | + type args struct { |
| 32 | + shimName string |
| 33 | + } |
| 34 | + tests := []struct { |
| 35 | + name string |
| 36 | + fields fields |
| 37 | + args args |
| 38 | + want string |
| 39 | + wantErr bool |
| 40 | + }{ |
| 41 | + { |
| 42 | + "shim not installed", |
| 43 | + fields{ |
| 44 | + tests.FixtureFs("../../testdata/node-installer/shim"), |
| 45 | + "/opt/kwasm", |
| 46 | + }, |
| 47 | + args{"not-existing-shim"}, |
| 48 | + "", |
| 49 | + false, |
| 50 | + }, |
| 51 | + { |
| 52 | + "missing shim binary", |
| 53 | + fields{ |
| 54 | + tests.FixtureFs("../../testdata/node-installer/shim-missing-binary"), |
| 55 | + "/opt/kwasm", |
| 56 | + }, |
| 57 | + args{"spin-v1"}, |
| 58 | + "/opt/kwasm/bin/containerd-shim-spin-v1", |
| 59 | + false, |
| 60 | + }, |
| 61 | + { |
| 62 | + "successful shim uninstallation", |
| 63 | + fields{ |
| 64 | + tests.FixtureFs("../../testdata/node-installer/shim"), |
| 65 | + "/opt/kwasm", |
| 66 | + }, |
| 67 | + args{"spin-v1"}, |
| 68 | + "/opt/kwasm/bin/containerd-shim-spin-v1", |
| 69 | + false, |
| 70 | + }, |
| 71 | + } |
| 72 | + for _, tt := range tests { |
| 73 | + t.Run(tt.name, func(t *testing.T) { |
| 74 | + c := &Config{ |
| 75 | + hostFs: tt.fields.hostFs, |
| 76 | + kwasmPath: tt.fields.kwasmPath, |
| 77 | + } |
| 78 | + |
| 79 | + got, err := c.Uninstall(tt.args.shimName) |
| 80 | + |
| 81 | + if (err != nil) != tt.wantErr { |
| 82 | + t.Errorf("Config.Uninstall() error = %v, wantErr %v", err, tt.wantErr) |
| 83 | + return |
| 84 | + } |
| 85 | + if got != tt.want { |
| 86 | + t.Errorf("Config.Uninstall() = %v, want %v", got, tt.want) |
| 87 | + } |
| 88 | + }) |
| 89 | + } |
| 90 | +} |
0 commit comments