blob: fb7b23fa3ed7d4916c658408c3bb83b0139d4e3a [file] [log] [blame] [edit]
// Copyright (C) 2018 GerritForge Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.gerritforge.analytics.gitcommits.model
import org.scalatest.{FlatSpec, Matchers}
import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Paths}
import scala.xml.XML
class GerritEndpointConfigTest extends FlatSpec with Matchers with ManifestXML {
"gerritProjectsUrl" should "contain prefix when available" in {
val prefix = "prefixMustBeThere"
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), prefix = Some(prefix))
conf.gerritProjectsUrl should contain(s"testBaseUrl/projects/?p=$prefix")
}
it should "not contain prefix when not available" in {
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), prefix = None)
conf.gerritProjectsUrl should contain(s"testBaseUrl/projects/")
}
"contributorsUrl" should "" in {
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), prefix = None)
conf.contributorsUrl(GerritProjectWithRef("opensbi","opensbi",Some("refs/tags/v0.8"))) should be
(Some(s"testBaseUrl/projects/opensbi/analytics~contributors?&starting-revision=refs/tags/v0.8"))
}
"projectsFromManifest" should "return projects contained in a repo manifest XML" in {
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), manifest = Option(manifestFile.getAbsolutePath))
val projectNamesFromManifest = conf.projectsFromManifest.toSeq.flatten.map(_.name)
projectNamesFromManifest should contain only ("sel4_projects_libs", "seL4_tools", "sel4runtime", "musllibc", "seL4_libs", "prefix/util_libs", "sel4test", "nanopb", "opensbi")
projectNamesFromManifest should not contain ("non-existent-project")
}
it should "return projects ids with URL encoded names mentioned in a repo manifest XML" in {
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), manifest = Option(manifestFile.getAbsolutePath))
val projectIdsFromManifest = conf.projectsFromManifest.toSeq.flatten.map(_.id)
projectIdsFromManifest should contain only ("sel4_projects_libs", "seL4_tools", "sel4runtime", "musllibc", "seL4_libs", "prefix%2Futil_libs", "sel4test", "nanopb", "opensbi")
}
it should "return projects with the version contained in a repo manifest XML with" in {
val conf = GerritEndpointConfig(baseUrl = Some("testBaseUrl"), manifest = Option(manifestFile.getAbsolutePath))
val projectNamesFromManifest = conf.projectsFromManifest.toSeq.flatten
projectNamesFromManifest should contain only (
GerritProjectWithRef("musllibc","musllibc",Some("sel4")),
GerritProjectWithRef("nanopb","nanopb",Some("refs/tags/0.4.3")),
GerritProjectWithRef("opensbi","opensbi",Some("refs/tags/v0.8")),
GerritProjectWithRef("prefix%2Futil_libs","prefix/util_libs",Some("master")),
GerritProjectWithRef("sel4_projects_libs","sel4_projects_libs",Some("master")),
GerritProjectWithRef("sel4runtime","sel4runtime",Some("master")),
GerritProjectWithRef("sel4test","sel4test",Some("master")),
GerritProjectWithRef("seL4_libs","seL4_libs",Some("master")),
GerritProjectWithRef("seL4_tools","seL4_tools",Some("master"))
)
}
}
trait ManifestXML {
// Sample from https://docs.sel4.systems/projects/buildsystem/repo-cheatsheet.html
lazy val manifestFile: File = {
val tmpFile = File.createTempFile("analytics-etl", s"-${System.nanoTime()}.xml")
Files.write(tmpFile.toPath,
"""<manifest>
|<remote name="seL4" fetch="." />
|<remote fetch="../sel4proj" name="sel4proj"/>
|<remote fetch="https://github.com/nanopb" name="nanopb" />
|<remote fetch="https://github.com/riscv" name="opensbi"/>
|
|<default revision="master" remote="seL4" />
|
|<project name="seL4_tools.git" path="tools/seL4">
| <linkfile src="cmake-tool/init-build.sh" dest="init-build.sh"/>
| <linkfile src="cmake-tool/griddle" dest="griddle"/>
|</project>
|<project name="sel4runtime.git" path="projects/sel4runtime"/>
|<project name="musllibc.git" path="projects/musllibc" revision="sel4"/>
|<project name="seL4_libs.git" path="projects/seL4_libs"/>
|<project name="prefix/util_libs.git" path="projects/util_libs"/>
|<project name="sel4test.git" path="projects/sel4test">
| <linkfile src="easy-settings.cmake" dest="easy-settings.cmake"/>
|</project>
|<project name="sel4_projects_libs" path="projects/sel4_projects_libs" />
|<project name="opensbi" remote="opensbi" revision="refs/tags/v0.8" path="tools/opensbi"/>
|<project name="nanopb" path="tools/nanopb" revision="refs/tags/0.4.3" upstream="master" remote="nanopb"/>
|</manifest>""".stripMargin.getBytes(StandardCharsets.UTF_8))
tmpFile
}
}