Lorenz Brun | 547b33f | 2020-04-23 15:27:06 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "bytes" |
| 21 | "strings" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | func Test_patchKconfig(t *testing.T) { |
| 26 | type args struct { |
| 27 | inFile string |
| 28 | overrides map[string]string |
| 29 | } |
| 30 | tests := []struct { |
| 31 | name string |
| 32 | args args |
| 33 | wantOutFile string |
| 34 | wantErr bool |
| 35 | }{ |
| 36 | { |
| 37 | "passthroughExtend", |
| 38 | args{inFile: "# TEST=y\n\n", overrides: map[string]string{"TEST": "n"}}, |
| 39 | "# TEST=y\n\nTEST=n\n", |
| 40 | false, |
| 41 | }, |
| 42 | { |
| 43 | "patch", |
| 44 | args{inFile: "TEST=y\nTEST_NO=n\n", overrides: map[string]string{"TEST": "n"}}, |
| 45 | "TEST=n\nTEST_NO=n\n", |
| 46 | false, |
| 47 | }, |
| 48 | } |
| 49 | for _, tt := range tests { |
| 50 | t.Run(tt.name, func(t *testing.T) { |
| 51 | outFile := &bytes.Buffer{} |
| 52 | if err := patchKconfig(strings.NewReader(tt.args.inFile), outFile, tt.args.overrides); (err != nil) != tt.wantErr { |
| 53 | t.Errorf("patchKconfig() error = %v, wantErr %v", err, tt.wantErr) |
| 54 | return |
| 55 | } |
| 56 | if gotOutFile := outFile.String(); gotOutFile != tt.wantOutFile { |
| 57 | t.Errorf("patchKconfig() = %v, want %v", gotOutFile, tt.wantOutFile) |
| 58 | } |
| 59 | }) |
| 60 | } |
| 61 | } |