Skip to content

Commit 3c96e9f

Browse files
author
Kamal Nasser
authored
apps: update component spec interfaces (#559)
* update app component spec interfaces * update interface AppBuildableComponentSpec to match functions components * add interfaces AppDockerBuildableComponentSpec and AppCNBBuildableComponentSpec * remove deprecated field/accessor GetEnvironmentSlug
1 parent 17dd063 commit 3c96e9f

File tree

4 files changed

+102
-96
lines changed

4 files changed

+102
-96
lines changed

apps.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -507,21 +507,30 @@ type AppBuildableComponentSpec interface {
507507
GetGitLab() *GitLabSourceSpec
508508

509509
GetSourceDir() string
510-
GetDockerfilePath() string
511-
GetBuildCommand() string
512-
GetEnvironmentSlug() string
513510

514511
GetEnvs() []*AppVariableDefinition
515512
}
516513

514+
// AppDockerBuildableComponentSpec is a component that is buildable from source using Docker.
515+
type AppDockerBuildableComponentSpec interface {
516+
AppBuildableComponentSpec
517+
518+
GetDockerfilePath() string
519+
}
520+
521+
// AppCNBBuildableComponentSpec is a component that is buildable from source using cloud native buildpacks.
522+
type AppCNBBuildableComponentSpec interface {
523+
AppBuildableComponentSpec
524+
525+
GetBuildCommand() string
526+
}
527+
517528
// AppContainerComponentSpec is a component that runs in a cluster.
518529
type AppContainerComponentSpec interface {
519530
AppBuildableComponentSpec
520531

521532
GetImage() *ImageSourceSpec
522-
523533
GetRunCommand() string
524-
525534
GetInstanceSizeSlug() string
526535
GetInstanceCount() int64
527536
}

apps_accessors.go

-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps_accessors_test.go

-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps_test.go

+88-16
Original file line numberDiff line numberDiff line change
@@ -658,38 +658,96 @@ func TestApps_Interfaces(t *testing.T) {
658658
})
659659

660660
t.Run("AppBuildableComponentSpec", func(t *testing.T) {
661-
for _, impl := range []interface{}{
662-
&AppServiceSpec{},
663-
&AppWorkerSpec{},
664-
&AppJobSpec{},
665-
&AppStaticSiteSpec{},
661+
for impl, wantMatch := range map[any]bool{
662+
&AppServiceSpec{}: true,
663+
&AppWorkerSpec{}: true,
664+
&AppJobSpec{}: true,
665+
&AppStaticSiteSpec{}: true,
666+
&AppFunctionsSpec{}: true,
667+
668+
&AppDatabaseSpec{}: false,
669+
} {
670+
_, ok := impl.(AppBuildableComponentSpec)
671+
if wantMatch && !ok {
672+
t.Fatalf("%T should match interface", impl)
673+
} else if !wantMatch && ok {
674+
t.Fatalf("%T should NOT match interface", impl)
675+
}
676+
}
677+
})
678+
679+
t.Run("AppDockerBuildableComponentSpec", func(t *testing.T) {
680+
for impl, wantMatch := range map[any]bool{
681+
&AppServiceSpec{}: true,
682+
&AppWorkerSpec{}: true,
683+
&AppJobSpec{}: true,
684+
&AppStaticSiteSpec{}: true,
685+
686+
&AppFunctionsSpec{}: false,
687+
&AppDatabaseSpec{}: false,
688+
} {
689+
_, ok := impl.(AppDockerBuildableComponentSpec)
690+
if wantMatch && !ok {
691+
t.Fatalf("%T should match interface", impl)
692+
} else if !wantMatch && ok {
693+
t.Fatalf("%T should NOT match interface", impl)
694+
}
695+
}
696+
})
697+
698+
t.Run("AppCNBBuildableComponentSpec", func(t *testing.T) {
699+
for impl, wantMatch := range map[any]bool{
700+
&AppServiceSpec{}: true,
701+
&AppWorkerSpec{}: true,
702+
&AppJobSpec{}: true,
703+
&AppStaticSiteSpec{}: true,
704+
705+
&AppFunctionsSpec{}: false,
706+
&AppDatabaseSpec{}: false,
666707
} {
667-
if _, ok := impl.(AppBuildableComponentSpec); !ok {
708+
_, ok := impl.(AppCNBBuildableComponentSpec)
709+
if wantMatch && !ok {
668710
t.Fatalf("%T should match interface", impl)
711+
} else if !wantMatch && ok {
712+
t.Fatalf("%T should NOT match interface", impl)
669713
}
670714
}
671715
})
672716

673717
t.Run("AppContainerComponentSpec", func(t *testing.T) {
674-
for _, impl := range []interface{}{
675-
&AppServiceSpec{},
676-
&AppWorkerSpec{},
677-
&AppJobSpec{},
718+
for impl, wantMatch := range map[any]bool{
719+
&AppServiceSpec{}: true,
720+
&AppWorkerSpec{}: true,
721+
&AppJobSpec{}: true,
722+
723+
&AppStaticSiteSpec{}: false,
724+
&AppFunctionsSpec{}: false,
725+
&AppDatabaseSpec{}: false,
678726
} {
679-
if _, ok := impl.(AppContainerComponentSpec); !ok {
727+
_, ok := impl.(AppContainerComponentSpec)
728+
if wantMatch && !ok {
680729
t.Fatalf("%T should match interface", impl)
730+
} else if !wantMatch && ok {
731+
t.Fatalf("%T should NOT match interface", impl)
681732
}
682733
}
683734
})
684735

685736
t.Run("AppRoutableComponentSpec", func(t *testing.T) {
686-
for _, impl := range []interface{}{
687-
&AppServiceSpec{},
688-
&AppStaticSiteSpec{},
689-
&AppFunctionsSpec{},
737+
for impl, wantMatch := range map[any]bool{
738+
&AppServiceSpec{}: true,
739+
&AppStaticSiteSpec{}: true,
740+
&AppFunctionsSpec{}: true,
741+
742+
&AppWorkerSpec{}: false,
743+
&AppJobSpec{}: false,
744+
&AppDatabaseSpec{}: false,
690745
} {
691-
if _, ok := impl.(AppRoutableComponentSpec); !ok {
746+
_, ok := impl.(AppRoutableComponentSpec)
747+
if wantMatch && !ok {
692748
t.Fatalf("%T should match interface", impl)
749+
} else if !wantMatch && ok {
750+
t.Fatalf("%T should NOT match interface", impl)
693751
}
694752
}
695753
})
@@ -717,6 +775,20 @@ func TestApps_Interfaces(t *testing.T) {
717775
t.Fatalf("%T should match interface", impl)
718776
}
719777
}
778+
for impl, wantMatch := range map[any]bool{
779+
&GitSourceSpec{}: true,
780+
&GitHubSourceSpec{}: true,
781+
&GitLabSourceSpec{}: true,
782+
783+
&ImageSourceSpec{}: false,
784+
} {
785+
_, ok := impl.(VCSSourceSpec)
786+
if wantMatch && !ok {
787+
t.Fatalf("%T should match interface", impl)
788+
} else if !wantMatch && ok {
789+
t.Fatalf("%T should NOT match interface", impl)
790+
}
791+
}
720792
})
721793
}
722794

0 commit comments

Comments
 (0)