(t *testing.T, when spec.G, it spec.S)
| 21 | } |
| 22 | |
| 23 | func testBuildpackageConfigReader(t *testing.T, when spec.G, it spec.S) { |
| 24 | when("#Read", func() { |
| 25 | var tmpDir string |
| 26 | |
| 27 | it.Before(func() { |
| 28 | var err error |
| 29 | tmpDir, err = os.MkdirTemp("", "buildpackage-config-test") |
| 30 | h.AssertNil(t, err) |
| 31 | }) |
| 32 | |
| 33 | it.After(func() { |
| 34 | os.RemoveAll(tmpDir) |
| 35 | }) |
| 36 | |
| 37 | it("returns default buildpack config", func() { |
| 38 | expected := buildpackage.Config{ |
| 39 | Buildpack: dist.BuildpackURI{ |
| 40 | URI: ".", |
| 41 | }, |
| 42 | Platform: dist.Platform{ |
| 43 | OS: "linux", |
| 44 | }, |
| 45 | } |
| 46 | actual := buildpackage.DefaultConfig() |
| 47 | |
| 48 | h.AssertEq(t, actual, expected) |
| 49 | }) |
| 50 | |
| 51 | it("returns default extension config", func() { |
| 52 | expected := buildpackage.Config{ |
| 53 | Extension: dist.BuildpackURI{ |
| 54 | URI: ".", |
| 55 | }, |
| 56 | Platform: dist.Platform{ |
| 57 | OS: "linux", |
| 58 | }, |
| 59 | } |
| 60 | actual := buildpackage.DefaultExtensionConfig() |
| 61 | |
| 62 | h.AssertEq(t, actual, expected) |
| 63 | }) |
| 64 | |
| 65 | it("returns correct config when provided toml file is valid", func() { |
| 66 | configFile := filepath.Join(tmpDir, "package.toml") |
| 67 | |
| 68 | err := os.WriteFile(configFile, []byte(validPackageToml), os.ModePerm) |
| 69 | h.AssertNil(t, err) |
| 70 | |
| 71 | packageConfigReader := buildpackage.NewConfigReader() |
| 72 | |
| 73 | config, err := packageConfigReader.Read(configFile) |
| 74 | h.AssertNil(t, err) |
| 75 | |
| 76 | h.AssertEq(t, config.Platform.OS, "windows") |
| 77 | h.AssertEq(t, config.Buildpack.URI, "https://example.com/bp/a.tgz") |
| 78 | h.AssertEq(t, len(config.Dependencies), 1) |
| 79 | h.AssertEq(t, config.Dependencies[0].URI, "https://example.com/bp/b.tgz") |
| 80 | }) |
nothing calls this directly
no test coverage detected