weldr: Add tests for V1 source API and better id support
This commit is contained in:
parent
40fc8a8734
commit
6bfa7a3e0e
1 changed files with 109 additions and 24 deletions
|
|
@ -980,39 +980,18 @@ func TestSourcesNew(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSourcesNewToml(t *testing.T) {
|
||||
func TestSourcesNewTomlV0(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
source := `
|
||||
sources := []string{`
|
||||
name = "fish"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`
|
||||
req := httptest.NewRequest("POST", "/api/v0/projects/source/new", bytes.NewReader([]byte(source)))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
require.Equal(t, http.StatusOK, r.StatusCode)
|
||||
|
||||
test.SendHTTP(api, true, "DELETE", "/api/v0/projects/source/delete/fish", ``)
|
||||
}
|
||||
|
||||
// Empty TOML, and invalid TOML should return an error
|
||||
func TestSourcesNewWrongToml(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
sources := []string{``, `
|
||||
[fish]
|
||||
`, `[fish]
|
||||
name = "fish"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
|
|
@ -1027,6 +1006,112 @@ check_gpg = false
|
|||
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
require.Equal(t, http.StatusOK, r.StatusCode)
|
||||
|
||||
test.SendHTTP(api, true, "DELETE", "/api/v0/projects/source/delete/fish", ``)
|
||||
}
|
||||
}
|
||||
|
||||
// Empty TOML, and invalid TOML should return an error
|
||||
func TestSourcesNewWrongTomlV0(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
sources := []string{``, `
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`}
|
||||
for _, source := range sources {
|
||||
req := httptest.NewRequest("POST", "/api/v0/projects/source/new", bytes.NewReader([]byte(source)))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSourcesNewTomlV1 tests the v1 sources API with id and name
|
||||
func TestSourcesNewTomlV1(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
sources := []string{`
|
||||
id = "fish"
|
||||
name = "fish or cut bait"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`, `[fish]
|
||||
name = "fish or cut bait"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`, `[fish]
|
||||
id = "fish"
|
||||
name = "fish or cut bait"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`}
|
||||
for _, source := range sources {
|
||||
req := httptest.NewRequest("POST", "/api/v1/projects/source/new", bytes.NewReader([]byte(source)))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
require.Equal(t, http.StatusOK, r.StatusCode)
|
||||
|
||||
test.SendHTTP(api, true, "DELETE", "/api/v1/projects/source/delete/fish", ``)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSourcesNewWrongTomlV1 Tests that Empty TOML, and invalid TOML should return an error
|
||||
func TestSourcesNewWrongTomlV1(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
sources := []string{``, `
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`, `
|
||||
[fish]
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`, `
|
||||
id = "fish"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`}
|
||||
for _, source := range sources {
|
||||
req := httptest.NewRequest("POST", "/api/v1/projects/source/new", bytes.NewReader([]byte(source)))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue