blob: f90c860fd41f2305e3ce3bc8f728932e696ac5b0 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
Lorenz Brun547b33f2020-04-23 15:27:06 +02002// SPDX-License-Identifier: Apache-2.0
Lorenz Brun547b33f2020-04-23 15:27:06 +02003
4package main
5
6import (
7 "bytes"
8 "strings"
9 "testing"
10)
11
12func Test_patchKconfig(t *testing.T) {
13 type args struct {
14 inFile string
15 overrides map[string]string
16 }
17 tests := []struct {
18 name string
19 args args
20 wantOutFile string
21 wantErr bool
22 }{
23 {
24 "passthroughExtend",
25 args{inFile: "# TEST=y\n\n", overrides: map[string]string{"TEST": "n"}},
26 "# TEST=y\n\nTEST=n\n",
27 false,
28 },
29 {
30 "patch",
31 args{inFile: "TEST=y\nTEST_NO=n\n", overrides: map[string]string{"TEST": "n"}},
32 "TEST=n\nTEST_NO=n\n",
33 false,
34 },
35 }
36 for _, tt := range tests {
37 t.Run(tt.name, func(t *testing.T) {
38 outFile := &bytes.Buffer{}
39 if err := patchKconfig(strings.NewReader(tt.args.inFile), outFile, tt.args.overrides); (err != nil) != tt.wantErr {
40 t.Errorf("patchKconfig() error = %v, wantErr %v", err, tt.wantErr)
41 return
42 }
43 if gotOutFile := outFile.String(); gotOutFile != tt.wantOutFile {
44 t.Errorf("patchKconfig() = %v, want %v", gotOutFile, tt.wantOutFile)
45 }
46 })
47 }
48}