@@ -2,7 +2,9 @@ package teamloader
22
33import (
44 "context"
5+ "io/fs"
56 "os"
7+ "path/filepath"
68 "testing"
79
810 "github.com/stretchr/testify/assert"
@@ -94,6 +96,40 @@ func TestCheckRequiredEnvVarsWithModelGateway(t *testing.T) {
9496 require .NoError (t , err )
9597}
9698
99+ func TestLoadExamples (t * testing.T ) {
100+ // Collect the missing env vars.
101+ missingEnvs := map [string ]bool {}
102+
103+ for _ , file := range collectExamples (t ) {
104+ t .Run (file , func (t * testing.T ) {
105+ _ , err := Load (t .Context (), file , config.RuntimeConfig {})
106+ if err != nil {
107+ envErr := & environment.RequiredEnvError {}
108+ require .ErrorAs (t , err , & envErr )
109+
110+ for _ , env := range envErr .Missing {
111+ missingEnvs [env ] = true
112+ }
113+ }
114+ })
115+ }
116+
117+ for name := range missingEnvs {
118+ t .Setenv (name , "dummy" )
119+ }
120+
121+ // Load all the examples.
122+ for _ , file := range collectExamples (t ) {
123+ t .Run (file , func (t * testing.T ) {
124+ t .Parallel ()
125+
126+ teams , err := Load (t .Context (), file , config.RuntimeConfig {})
127+ require .NoError (t , err )
128+ require .NotEmpty (t , teams )
129+ })
130+ }
131+ }
132+
97133func openRoot (t * testing.T , dir string ) * os.Root {
98134 t .Helper ()
99135
@@ -103,3 +139,22 @@ func openRoot(t *testing.T, dir string) *os.Root {
103139
104140 return root
105141}
142+
143+ func collectExamples (t * testing.T ) []string {
144+ t .Helper ()
145+
146+ var files []string
147+ err := filepath .WalkDir (filepath .Join (".." , ".." , "examples" ), func (path string , d fs.DirEntry , err error ) error {
148+ if err != nil {
149+ return err
150+ }
151+ if ! d .IsDir () && filepath .Ext (path ) == ".yaml" {
152+ files = append (files , path )
153+ }
154+ return nil
155+ })
156+ require .NoError (t , err )
157+ assert .NotEmpty (t , files )
158+
159+ return files
160+ }
0 commit comments