@@ -4,10 +4,10 @@ import (
44 "context"
55 "os"
66 "reflect"
7+ "strings"
78 "testing"
89
910 "github.com/rs/zerolog"
10- "github.com/rs/zerolog/log"
1111)
1212
1313func stringSliceEqual (a , b []string ) bool {
@@ -24,21 +24,6 @@ func stringSliceEqual(a, b []string) bool {
2424
2525var testContext = zerolog .New (os .Stdout ).With ().Timestamp ().Logger ().WithContext (context .Background ())
2626
27- func TestAppJsonBuildpackPatch (t * testing.T ) {
28- a := AppJSON {
29- Buildpacks : []Buildpack {
30- {URL : "heroku/nodejs" },
31- {URL : "heroku/python" },
32- },
33- Stack : "heroku-20" ,
34- ctx : log .With ().Logger ().WithContext (context .Background ()),
35- }
36- expected := []string {"urn:cnb:builder:heroku/nodejs" , "urn:cnb:builder:heroku/python" }
37- if ! stringSliceEqual (a .GetBuildpacks (), expected ) {
38- t .Errorf ("expected %s, got %s" , expected , a .GetBuildpacks ())
39- }
40- }
41-
4227func TestAppJsonMissing (t * testing.T ) {
4328 a := AppJSON {
4429 reader : func () ([]byte , error ) {
@@ -58,27 +43,49 @@ func TestAppJsonMissing(t *testing.T) {
5843func TestAppJsonStack (t * testing.T ) {
5944 a := AppJSON {
6045 reader : func () ([]byte , error ) {
61- return []byte (`{"stack": "heroku-18 "}` ), nil
46+ return []byte (`{"stack": "heroku-22 "}` ), nil
6247 },
6348 ctx : testContext ,
6449 }
6550 err := a .Unmarshal ()
6651 if err != nil {
6752 t .Errorf ("expected no error, got %s" , err )
6853 }
69- if a .Stack != "heroku-18 " {
54+ if a .Stack != "heroku-22 " {
7055 t .Errorf ("expected heroku-22, got %s" , a .Stack )
7156 }
7257}
7358
7459func TestAppJsonBuilders (t * testing.T ) {
75- a := AppJSON {
76- Stack : "heroku-22" ,
77- ctx : testContext ,
60+ tests := []struct {
61+ stack string
62+ expected []string
63+ }{
64+ {"heroku-22" , []string {"heroku/builder:22" , "heroku/heroku:22-cnb" }},
65+ {"custom/builder:latest" , []string {"custom/builder:latest" }},
66+ }
67+ for _ , tt := range tests {
68+ a := AppJSON {Stack : tt .stack , ctx : testContext }
69+ if ! stringSliceEqual (a .GetBuilders (), tt .expected ) {
70+ t .Errorf ("stack %s: expected %s, got %s" , tt .stack , tt .expected , a .GetBuilders ())
71+ }
7872 }
79- expected := []string {"heroku/builder:22" , "heroku/heroku:22-cnb" }
80- if ! stringSliceEqual (a .GetBuilders (), expected ) {
81- t .Errorf ("expected %s, got %s" , expected , a .GetBuilders ())
73+ }
74+
75+ func TestAppJsonEOLStackError (t * testing.T ) {
76+ for _ , stack := range EOLStacks {
77+ a := AppJSON {
78+ reader : func () ([]byte , error ) {
79+ return []byte (`{"stack": "` + stack + `"}` ), nil
80+ },
81+ ctx : testContext ,
82+ }
83+ err := a .Unmarshal ()
84+ if err == nil {
85+ t .Errorf ("stack %s: expected error for EOL stack, got nil" , stack )
86+ } else if ! strings .Contains (err .Error (), "end-of-life" ) {
87+ t .Errorf ("stack %s: expected end-of-life error, got: %s" , stack , err )
88+ }
8289 }
8390}
8491
0 commit comments