Skip to content

Commit

Permalink
Issue.path resolution (#48)
Browse files Browse the repository at this point in the history
* Extracts Path resolution

* Corrects test case

* Uses updated FileKit api

* Adds Test case
  • Loading branch information
Aaron Liberatore authored Nov 18, 2017
1 parent a673244 commit 5a295cf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 122 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
## Build generated
build/
DerivedData/
.DS_Store

## Various settings
*.pbxuser
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/IBM-Swift/LoggerAPI.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/IBM-Swift/LoggerAPI.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/IBM-Swift/FileKit.git", .upToNextMajor(from: "0.0.1"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "Configuration",
dependencies: ["LoggerAPI"]
dependencies: ["LoggerAPI", "FileKit"]
),
.testTarget(
name: "ConfigurationTests",
Expand Down
7 changes: 4 additions & 3 deletions Sources/Configuration/ConfigurationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import Foundation
import LoggerAPI
import FileKit

/// ConfigurationManager class
///
Expand Down Expand Up @@ -79,11 +80,11 @@ public class ConfigurationManager {
public var path: String {
switch self {
case .executable:
return executableFolder
return FileKit.executableFolder
case .pwd:
return presentWorkingDirectory
return FileKit.workingDirectory
case .project:
return projectFolder
return FileKit.projectFolder
case .customPath(let path):
return path
}
Expand Down
115 changes: 0 additions & 115 deletions Sources/Configuration/PathUtilities.swift

This file was deleted.

12 changes: 10 additions & 2 deletions Tests/ConfigurationTests/ConfigurationManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import XCTest
import Foundation
import FileKit
@testable import Configuration

class ConfigurationManagerTest: XCTestCase {
Expand All @@ -32,9 +33,12 @@ class ConfigurationManagerTest: XCTestCase {

static let testJSONURL = URL(fileURLWithPath: #file).appendingPathComponent("../test.json").standardized

static let symlinkInPWD = URL(fileURLWithPath: "test.json")
static let symlinkInPWD = { () -> URL in
var pwd = FileKit.workingDirectoryURL.appendingPathComponent("test.json")
return FileKit.executableURL.path.hasSuffix("/xctest") ? pwd : URL(fileURLWithPath: "test.json")
}()

static let symlinkInExecutableFolder = URL(fileURLWithPath: executableFolder).appendingPathComponent("test.json").standardized
static let symlinkInExecutableFolder = URL(fileURLWithPath: FileKit.executableFolder).appendingPathComponent("test.json").standardized

let jsonString = "{\n \"env\": \"<default>\",\n \"OAuth\": {\n \"name\": \"facebook\",\n \"configuration\": {\n \"clientID\": \"<default>\",\n \"clientSecret\": \"<default>\",\n \"profileFields\": [\"displayName\", \"emails\", \"id\", \"name\"],\n \"profileURL\": \"https://graph.facebook.com/v2.6/me\",\n \"scope\": [\"email\"],\n \"state\": true\n }\n },\n \"port\": \"<default>\"\n}"

Expand Down Expand Up @@ -172,6 +176,10 @@ class ConfigurationManagerTest: XCTestCase {
manager = ConfigurationManager().load(file: "test.json", relativeFrom: .pwd)
XCTAssertEqual(manager["OAuth:configuration:state"] as? Bool, true)

// Project Folder
manager = ConfigurationManager().load(file: "test.json", relativeFrom: .project)
XCTAssertEqual(manager["OAuth:configuration:state"] as? Bool, true)

// Executable
manager = ConfigurationManager().load(file: "test.json", relativeFrom: .executable)
XCTAssertEqual(manager["OAuth:configuration:state"] as? Bool, true)
Expand Down

0 comments on commit 5a295cf

Please sign in to comment.