Skip to content

Commit

Permalink
added tests for successful installation source parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkmorestupidless committed Apr 19, 2023
1 parent e28700d commit f9ad435
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cmtc/src/main/scala/com/lunatech/cmt/client/cli/ArgParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object ArgParsers {

given installationSourceArgParser: ArgParser[InstallationSource] = {

val githubProjectRegex = "(.*)\\/(.*)".r
val githubProjectRegex = "([A-Za-z0-9-_]*)\\/([A-Za-z0-9-_]*)".r

def toString(installationSource: InstallationSource): String =
installationSource match {
Expand Down Expand Up @@ -69,11 +69,11 @@ object ArgParsers {
// no
// - error - i don't know what to do
(maybeFile.exists(), maybeFile.isDirectory, str.endsWith(".zip"), maybeGithub) match {
case (true, true, _, _) => LocalDirectory(maybeFile).asRight
case (true, false, true, _) => ZipFile(maybeFile).asRight
case (true, false, false, _) => Other(s"'$str' is a file but not a zip file - i'm afraid I don't know how to install a course from this file").asLeft
case (true, true, _, _) => LocalDirectory(maybeFile).asRight
case (true, false, true, _) => ZipFile(maybeFile).asRight
case (true, false, false, _) => Other(s"'$str' is a file but not a zip file - i'm afraid I don't know how to install a course from this file").asLeft
case (false, _, _, Some(githubProject)) => githubProject.asRight
case (_, _, _, _) => Other(s"'$str' is not a local directory or zip file and it doesn't appear to be a Github project either. I'm afraid I don't know how to deal with this.").asLeft
case (_, _, _, _) => Other(s"'$str' is not a local directory or zip file and it doesn't appear to be a Github project either. I'm afraid I don't know how to deal with this.").asLeft
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.lunatech.cmt.client.cli

import caseapp.Parser
import caseapp.core.Error.Other
import com.lunatech.cmt.client.Domain.InstallationSource.{GithubProject, LocalDirectory, ZipFile}
import com.lunatech.cmt.client.command.{GotoExercise, Install}
import com.lunatech.cmt.support.TestDirectories
import sbt.io.syntax.{File, file}
import com.lunatech.cmt.client.cli.ArgParsers.given

final class InstallArgumentsSpec extends CommandLineArgumentsSpec[Install.Options] with TestDirectories {

val identifier = "install"

val parser: Parser[Install.Options] = Parser.derive

def invalidArguments(tempDirectory: File) = invalidArgumentsTable()

def validArguments(tempDirectory: File) = validArgumentsTable(
(
Seq("-s", baseDirectory.getAbsolutePath),
Install.Options(LocalDirectory(baseDirectory))),
(
Seq("-s", zippedCourse),
Install.Options(ZipFile(file(zippedCourse)))),
(
Seq("-s", "bleep/bloop"),
Install.Options(GithubProject(organisation = "bleep", project = "bloop")))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ trait TestDirectories {
val firstRealDirectory = adaptToOSSeparatorChar(s"$baseDirectory/cmta/src/test/resources/i-am-a-directory")
val secondRealDirectory = adaptToOSSeparatorChar(s"$baseDirectory/cmta/src/test/resources/i-am-another-directory")
val realFile = adaptToOSSeparatorChar(s"$baseDirectory/cmta/src/test/resources/i-am-a-file.txt")

val zippedCourse = adaptToOSSeparatorChar(s"$baseDirectoryGitRoot/functional-tests/src/test/resources/simple-repo.zip")
}

0 comments on commit f9ad435

Please sign in to comment.