Skip to content

Commit 81560d6

Browse files
rorybyrnebfirsh
authored andcommitted
chore: test for loading Config from YAML
Signed-off-by: synek <[email protected]>
1 parent d985a6f commit 81560d6

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pkg/config/load_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package config
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"path"
7+
"testing"
8+
9+
"github.com/replicate/cog/pkg/model"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
const TEST_CONFIG = `model: "model.py:SomeModel"
14+
environment:
15+
architectures:
16+
- cpu
17+
python_version: "3.8"
18+
python_requirements: requirements.txt
19+
system_packages:
20+
- libgl1-mesa-glx
21+
- libglib2.0-0
22+
examples:
23+
- input:
24+
input: "@example/foo.jpg"
25+
- input:
26+
input: "@example/bar.jpg"
27+
`
28+
29+
func TestGetProjectDirWithFlagSet(t *testing.T) {
30+
projectDirFlag := "foo"
31+
32+
projectDir, err := GetProjectDir(projectDirFlag)
33+
require.NoError(t, err)
34+
require.Equal(t, projectDir, projectDirFlag)
35+
}
36+
37+
func TestGetConfigShouldLoadFromFile(t *testing.T) {
38+
dir, err := ioutil.TempDir("/tmp/", "cog-test")
39+
require.NoError(t, err)
40+
defer os.RemoveAll(dir)
41+
42+
err = ioutil.WriteFile(path.Join(dir, "cog.yaml"), []byte(TEST_CONFIG), 0644)
43+
require.NoError(t, err)
44+
t.Log(dir)
45+
conf, _, err := GetConfig(dir)
46+
require.NoError(t, err)
47+
want := &model.Config{
48+
Model: "model.py:SomeModel",
49+
Environment: &model.Environment{
50+
PythonVersion: "3.8",
51+
PythonRequirements: "requirements.txt",
52+
Architectures: []string{
53+
"cpu",
54+
},
55+
SystemPackages: []string{
56+
"libgl1-mesa-glx",
57+
"libglib2.0-0",
58+
},
59+
},
60+
Examples: []*model.Example{
61+
{
62+
Input: map[string]string{
63+
"input": "@example/foo.jpg",
64+
},
65+
},
66+
{
67+
Input: map[string]string{
68+
"input": "@example/bar.jpg",
69+
},
70+
},
71+
},
72+
}
73+
require.Equal(t, want, conf)
74+
}

0 commit comments

Comments
 (0)