-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_test.go
61 lines (49 loc) · 1.36 KB
/
in_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package resource_test
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
resource "github.com/taylorsilva/static-list-resource"
)
type InTestSuite struct {
suite.Suite
*require.Assertions
}
func (c *InTestSuite) TestReturnVersion() {
request := resource.InRequest{
Source: resource.Source{
List: []string{"item1", "item2", "item3", "item4", "item5"},
},
Version: resource.Version{Item: "item4"},
}
tmpdir := c.T().TempDir()
in := resource.NewIn()
response, err := in.Run(request, tmpdir)
expected := resource.InResponse{
Version: resource.Version{Item: "item4"},
}
c.NoError(err)
c.Equal(expected, response, "given item4 it should return item4")
file := filepath.Join(tmpdir, "item")
c.FileExists(file)
contents, _ := os.ReadFile(file)
c.Equal([]byte(`item4`), contents)
}
func (c *InTestSuite) TestVersionNotFound() {
request := resource.InRequest{
Source: resource.Source{
List: []string{"item1", "item2", "item3", "item4", "item5"},
},
Version: resource.Version{Item: "other"},
}
tmpdir := c.T().TempDir()
in := resource.NewIn()
response, err := in.Run(request, tmpdir)
c.Equal(response, resource.InResponse{})
c.EqualError(err, "selected item not found in source.list")
}
func TestInSuite(t *testing.T) {
suite.Run(t, &InTestSuite{Assertions: require.New(t)})
}