| 1 | /* |
| 2 | Copyright The containerd 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 main |
| 18 | |
| 19 | import "testing" |
| 20 | |
| 21 | func TestReadConfigFrom(t *testing.T) { |
| 22 | testcases := []struct { |
| 23 | name string |
| 24 | toml string |
| 25 | }{ |
| 26 | { |
| 27 | name: "empty", |
| 28 | toml: `version="unstable"`, |
| 29 | }, |
| 30 | { |
| 31 | name: "generator", |
| 32 | toml: ` |
| 33 | version="unstable" |
| 34 | generator="go" |
| 35 | `, |
| 36 | }, |
| 37 | { |
| 38 | name: "generators", |
| 39 | toml: ` |
| 40 | version="unstable" |
| 41 | generators=["go"] |
| 42 | `, |
| 43 | }, |
| 44 | } |
| 45 | |
| 46 | for _, tc := range testcases { |
| 47 | t.Run(tc.name, func(t *testing.T) { |
| 48 | c, err := readConfigFrom([]byte(tc.toml)) |
| 49 | if err != nil { |
| 50 | t.Fatalf("err must be nil, but got %v", err) |
| 51 | } |
| 52 | if c.Generator == "go" { |
| 53 | t.Fatalf("Generator must be cleared, but got %v", c.Generator) |
| 54 | } |
| 55 | if len(c.Generators) != 1 || c.Generators[0] != "go" { |
| 56 | t.Fatalf("Generators must be [go], but got %v", c.Generators) |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | } |