api: add blueprints changes route

For each blueprint name passed to the route, a list of the changes to
that blueprint will be returned.

weldr/tests: add blueprint changes test

In order to test blueprint changes a blueprint must be created with a
unique id. Blueprint changes are not deleted when the blueprint is
deleted so in order to test this against lorax the blueprint must have
not been used/tested before. This id is created from a random int. The
test creates and deletes the same blueprint twice to check that each
creation updates the list of changes.
This commit is contained in:
Jacob Kozol 2019-11-12 14:08:16 +01:00 committed by Tom Gundersen
parent 080bd4968c
commit 9970150ed5
2 changed files with 86 additions and 0 deletions

View file

@ -5,13 +5,16 @@ import (
"context"
"encoding/json"
"io/ioutil"
"math/rand"
"net"
"net/http"
"net/http/httptest"
"os"
"reflect"
"strconv"
"strings"
"testing"
"time"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/store"
@ -298,6 +301,21 @@ func TestBlueprintsDelete(t *testing.T) {
}
}
func TestBlueprintsChanges(t *testing.T) {
api := weldr.New(repo, packages, nil, store.New(nil))
rand.Seed(time.Now().UnixNano())
id := strconv.Itoa(rand.Int())
ignoreFields := []string{"commit", "timestamp"}
sendHTTP(api, true, "POST", "/api/v0/blueprints/new", `{"name":"`+id+`","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.0"}`)
testRoute(t, api, true, "GET", "/api/v0/blueprints/changes/failing"+id, ``, http.StatusOK, `{"blueprints":[],"errors":[{"id":"UnknownBlueprint","msg":"failing`+id+`"}],"limit":20,"offset":0}`, ignoreFields...)
testRoute(t, api, true, "GET", "/api/v0/blueprints/changes/"+id, ``, http.StatusOK, `{"blueprints":[{"changes":[{"commit":"","message":"Recipe `+id+`, version 0.0.0 saved.","revision":null,"timestamp":""}],"name":"`+id+`","total":1}],"errors":[],"limit":20,"offset":0}`, ignoreFields...)
sendHTTP(api, true, "DELETE", "/api/v0/blueprints/delete/"+id, ``)
sendHTTP(api, true, "POST", "/api/v0/blueprints/new", `{"name":"`+id+`","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.0"}`)
testRoute(t, api, true, "GET", "/api/v0/blueprints/changes/"+id, ``, http.StatusOK, `{"blueprints":[{"changes":[{"commit":"","message":"Recipe `+id+`, version 0.0.0 saved.","revision":null,"timestamp":""},{"commit":"","message":"Recipe `+id+`, version 0.0.0 saved.","revision":null,"timestamp":""}],"name":"`+id+`","total":2}],"errors":[],"limit":20,"offset":0}`, ignoreFields...)
sendHTTP(api, true, "DELETE", "/api/v0/blueprints/delete/"+id, ``)
}
func TestCompose(t *testing.T) {
var cases = []struct {
External bool