Use correct long description from DSA long RDF
- use date and DSA number as version identifier - add tests for Check and Get calls
This commit is contained in:
parent
12b2d36004
commit
182f21944b
5 changed files with 98 additions and 11 deletions
|
@ -1,10 +1,11 @@
|
||||||
FROM golang:1.19-bullseye AS builder
|
FROM golang:1.19-bullseye AS builder
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY go.mod /build/
|
COPY go.mod go.sum /build/
|
||||||
COPY cmd /build/cmd/
|
COPY cmd /build/cmd/
|
||||||
COPY internal /build/internal/
|
COPY internal /build/internal/
|
||||||
|
|
||||||
|
RUN go test -v ./...
|
||||||
RUN CGO_ENABLED=0 go build ./cmd/debian-dsa
|
RUN CGO_ENABLED=0 go build ./cmd/debian-dsa
|
||||||
|
|
||||||
FROM alpine:3
|
FROM alpine:3
|
||||||
|
|
8
go.mod
8
go.mod
|
@ -1,3 +1,11 @@
|
||||||
module git.dittberner.info/concourse-dsa-resource
|
module git.dittberner.info/concourse-dsa-resource
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/stretchr/objx v0.5.0 // indirect
|
||||||
|
github.com/stretchr/testify v1.8.1 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|
17
go.sum
Normal file
17
go.sum
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -81,8 +81,8 @@ func getRdfData(full bool) (*rdfData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Version struct {
|
type Version struct {
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
Title string `json:"title"`
|
DSANumber string `json:"dsa"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Version) String() string {
|
func (v Version) String() string {
|
||||||
|
@ -104,6 +104,7 @@ type getInput struct {
|
||||||
|
|
||||||
type MetaData struct {
|
type MetaData struct {
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
|
Package string `json:"package"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@ func (r *VersionRange) Len() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *VersionRange) Less(i, j int) bool {
|
func (r *VersionRange) Less(i, j int) bool {
|
||||||
return r.versions[i].Date <= r.versions[j].Date && r.versions[i].Title < r.versions[j].Title
|
return r.versions[i].Date <= r.versions[j].Date && r.versions[i].DSANumber < r.versions[j].DSANumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *VersionRange) Swap(i, j int) {
|
func (r *VersionRange) Swap(i, j int) {
|
||||||
|
@ -161,7 +162,9 @@ func (r *Resource) Check() error {
|
||||||
dates := &VersionRange{}
|
dates := &VersionRange{}
|
||||||
|
|
||||||
for _, item := range dsaData.Items {
|
for _, item := range dsaData.Items {
|
||||||
dates.addVersion(Version{Date: item.Date, Title: item.Title})
|
parts := strings.SplitN(item.Title, " ", 2)
|
||||||
|
|
||||||
|
dates.addVersion(Version{Date: item.Date, DSANumber: parts[0]})
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(dates)
|
sort.Sort(dates)
|
||||||
|
@ -185,19 +188,26 @@ func (r *Resource) Get(_ string) error {
|
||||||
return fmt.Errorf("could not interpret version from Concourse as date: %w", err)
|
return fmt.Errorf("could not interpret version from Concourse as date: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dsaData, err := getRdfData(false)
|
dsaData, err := getRdfData(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("could not get DSA RDF data: %v", err)
|
log.Fatalf("could not get DSA RDF data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range dsaData.Items {
|
for _, item := range dsaData.Items {
|
||||||
if item.Date == input.Version.Date && item.Title == input.Version.Title {
|
if item.Date == input.Version.Date && strings.HasPrefix(item.Title, input.Version.DSANumber) {
|
||||||
|
parts := strings.SplitN(item.Title, " ", 3)
|
||||||
|
|
||||||
err = r.writeGetOutput(Version{
|
err = r.writeGetOutput(Version{
|
||||||
Date: item.Date,
|
Date: item.Date,
|
||||||
Title: item.Title,
|
DSANumber: parts[0],
|
||||||
}, MetaData{
|
}, MetaData{
|
||||||
Link: item.Link,
|
Link: item.Link,
|
||||||
Description: strings.TrimSpace(item.Description),
|
Package: parts[1],
|
||||||
|
Description: strings.TrimSpace(
|
||||||
|
strings.ReplaceAll(strings.ReplaceAll(
|
||||||
|
item.Description, "<p>", ""), "</p>", "\n",
|
||||||
|
),
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
51
internal/resource/dsa/dsa_test.go
Normal file
51
internal/resource/dsa/dsa_test.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package dsa
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestResource_Check(t *testing.T) {
|
||||||
|
input := strings.NewReader("{}")
|
||||||
|
output := &bytes.Buffer{}
|
||||||
|
|
||||||
|
resource := NewResource(input, output)
|
||||||
|
|
||||||
|
err := resource.Check()
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
result := output.String()
|
||||||
|
|
||||||
|
assert.NotEmpty(t, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResource_Get(t *testing.T) {
|
||||||
|
rdf, err := getRdfData(false)
|
||||||
|
|
||||||
|
item := rdf.Items[0]
|
||||||
|
|
||||||
|
parts := strings.SplitN(item.Title, " ", 2)
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
input := strings.NewReader(fmt.Sprintf(
|
||||||
|
`{"source":{},"params":{},"version":{"date":"%s","dsa":"%s"}}`, item.Date, parts[0],
|
||||||
|
))
|
||||||
|
output := &bytes.Buffer{}
|
||||||
|
|
||||||
|
resource := NewResource(input, output)
|
||||||
|
|
||||||
|
err = resource.Get("/tmp")
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
result := output.String()
|
||||||
|
|
||||||
|
assert.NotEmpty(t, result)
|
||||||
|
}
|
Loading…
Reference in a new issue