MCPcopy Index your code
hub / github.com/docker/docker-agent / TestLoadExamples

Function TestLoadExamples

pkg/teamloader/teamloader_test.go:87–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestLoadExamples(t *testing.T) {
88 examples := collectExamples(t)
89
90 // Set every env var referenced by the examples to a dummy value so model
91 // and tool initialisation succeeds without real credentials.
92 for env := range gatherExampleEnvVars(t, examples) {
93 t.Setenv(env, "dummy")
94 }
95
96 for _, agentFilename := range examples {
97 t.Run(agentFilename, func(t *testing.T) {
98 t.Parallel()
99
100 data, err := os.ReadFile(agentFilename)
101 require.NoError(t, err)
102
103 // Examples must not pin a version: they should always parse with
104 // the latest config schema.
105 var v struct {
106 Version string `yaml:"version"`
107 }
108 require.NoError(t, yaml.Unmarshal(data, &v))
109 require.Empty(t, v.Version, "example %s should not define a version", agentFilename)
110
111 // Use a file source so the config's directory is known: examples
112 // such as instruction_file.yaml reference sibling files that are
113 // resolved relative to it at load time. A temp WorkingDir still
114 // redirects toolsets that write to disk (memory, RAG, cache, ...)
115 // away from the examples/ tree.
116 agentSource := config.NewFileSource(agentFilename)
117 runConfig := &config.RuntimeConfig{}
118 runConfig.WorkingDir = t.TempDir()
119
120 teams, err := Load(catalogContext(t), agentSource, runConfig, withTestProviderRegistry()...)
121 if errors.Is(err, dmr.ErrNotInstalled) {
122 t.Skipf("Skipping %s: Docker Model Runner not installed", agentFilename)
123 }
124 require.NoError(t, err)
125 assert.NotEmpty(t, teams)
126 })
127 }
128}
129
130// gatherExampleEnvVars returns the union of env vars referenced by the given
131// example files (both for models and toolsets). The set is collected up-front

Callers

nothing calls this directly

Calls 8

NewFileSourceFunction · 0.92
gatherExampleEnvVarsFunction · 0.85
catalogContextFunction · 0.85
withTestProviderRegistryFunction · 0.85
ReadFileMethod · 0.80
collectExamplesFunction · 0.70
LoadFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected