Skip to content

Commit e1dd3d1

Browse files
committed
tests: add tests on generateImports
1 parent 6f11522 commit e1dd3d1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/commands/internal/imports_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package internal
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func Test_generateImports(t *testing.T) {
13+
cfg := &Configuration{
14+
Version: "v1.57.0",
15+
Plugins: []*Plugin{
16+
{
17+
Module: "example.org/foo/bar",
18+
Import: "example.org/foo/bar/test",
19+
Version: "v1.2.3",
20+
},
21+
{
22+
Module: "example.com/foo/bar",
23+
Import: "example.com/foo/bar/test",
24+
Path: "/my/path",
25+
},
26+
},
27+
}
28+
29+
data, err := generateImports(cfg)
30+
require.NoError(t, err)
31+
32+
expected, err := os.ReadFile(filepath.Join("testdata", "imports.go"))
33+
require.NoError(t, err)
34+
35+
assert.Equal(t, expected, data)
36+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import (
4+
_ "example.com/foo/bar/test"
5+
_ "example.org/foo/bar/test"
6+
)

0 commit comments

Comments
 (0)