Verify that custom resource can be used for get requests
[finishes
@@ -96,4 +96,84 @@ var _ = Describe("Get version of a resource", func() {
})
+ Context("whose type is a custom resource type", func() {
+ var (
+ quineCheck string
+ quineIn string
+ quineOut string
+
+ resourceGet ResourceGet
+ )
+
+ BeforeEach(func() {
+ quineIn = `#!/bin/bash
+
+ TMPDIR=${TMPDIR:-/tmp}
+
+ exec 3>&1 # make stdout available as fd 3 for the result
+ exec 1>&2 # redirect all output to stderr for logging
+
+ payload=$TMPDIR/request
+ cat > $payload <&0
+
+ destination=$1
+
+ cp -a / $destination/ || true
+
+ version=$(jq -r '.version // ""' < $payload)
+
+ echo $version > $destination/version
+ `
+ c := NewResourceContainer(quineCheck, quineIn, quineOut)
+
+ r, err := c.RootFSify()
+ Expect(err).NotTo(HaveOccurred())
+
+ rootFSPath, err := createBaseResourceVolume(r)
+ Expect(err).ToNot(HaveOccurred())
+
+ quineResourceType := BaseResourceType{
+ RootFSPath: rootFSPath,
+ Name: "quine",
+ }
+
+ resourceGet = ResourceGet{
+ Resource: Resource{
+ ResourceType: ResourceGet{
+ Resource: Resource{
+ ResourceType: quineResourceType,
+ Source: atc.Source{},
+ },
+ Version: atc.Version{
+ "beep": "boop",
+ },
+ },
+ Source: atc.Source{
+ "versions": []atc.Version{
+ {"abc": "123"},
+ },
+ },
+ },
+ Version: atc.Version{
+ "yellow": "blue",
+ },
+ }
+ })
+
+ It("works", func() {
+ getVolume, getErr := resourceGet.Get(logger, testWorker)
+ Expect(getErr).NotTo(HaveOccurred())
+
+ file, err := getVolume.StreamOut("/version")
+ Expect(err).ToNot(HaveOccurred())
+ defer file.Close()
+
+ tarReader := tar.NewReader(file)
+ tarReader.Next()
+
+ bytes, err := ioutil.ReadAll(tarReader)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(bytes).To(MatchJSON(`{"yellow": "blue"}`))
+ })
+ })
})
