Skip to content

Commit

Permalink
Merge pull request #7 from turkenh/fix-null
Browse files Browse the repository at this point in the history
Fix null parsing issue
  • Loading branch information
turkenh authored May 21, 2019
2 parents e670069 + 8c2cfab commit e53108c
Show file tree
Hide file tree
Showing 27 changed files with 369 additions and 159 deletions.
52 changes: 51 additions & 1 deletion KubeContextTests/KubeContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class KubeContextLoadTwoContextTests: XCTestCase {
XCTFail()
}
XCTAssertNotNil(config)
XCTAssertEqual(config?.Contexts.count, 2, "There is two contexts")
XCTAssertEqual(config?.Contexts.count, 2, "There are two contexts")
XCTAssertEqual(config?.Contexts[0].Name, "kubernetes-admin@kubernetes", "Name of the context is correct")
XCTAssertEqual(config?.Contexts[0].Context.Cluster, "kubernetes", "Cluster of the context is correct")
XCTAssertEqual(config?.Contexts[0].Context.AuthInfo, "kubernetes-admin", "User of the context is correct")
Expand All @@ -164,3 +164,53 @@ class KubeContextLoadTwoContextTests: XCTestCase {

}
}

class KubeContextLoadConfigWithNullTests: XCTestCase {
let fileManager = FileManager.default

var k8s: Kubernetes?
var bundle: Bundle!
var url: URL!

override func setUp() {
bundle = Bundle(for: type(of: self))
var tempDataUrl: URL?
do {
let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
tempDataUrl = documentDirectory.appendingPathComponent("TempData")
try fileManager.removeItem(at: tempDataUrl!)
let testDataPath = bundle.resourcePath! + "/TestData"
try fileManager.copyItem(atPath: testDataPath, toPath: tempDataUrl!.path)
} catch {
XCTFail()
}

url = tempDataUrl!.appendingPathComponent("config-with-null.yaml")
k8s = Kubernetes()
XCTAssertNoThrow(try k8s?.setKubeconfig(configFile: url))
XCTAssertNotNil(k8s)
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testKubernetesLoadConfig() {
var config: Config?
do {
config = try k8s?.getConfig()
} catch {
XCTFail()
}
XCTAssertNotNil(config)
XCTAssertEqual(config?.Contexts.count, 2, "There are two contexts")
XCTAssertEqual(config?.Contexts[0].Name, "dev", "Name of the context is correct")
XCTAssertEqual(config?.Contexts[0].Context.Cluster, "dev-cluster", "Cluster of the context is correct")
XCTAssertEqual(config?.Contexts[0].Context.AuthInfo, "dev-user", "User of the context is correct")
XCTAssertNil(config?.Contexts[0].Context.Namespace)

XCTAssertEqual(config?.Clusters.count, 2, "There are two clusters")
XCTAssertEqual(config?.AuthInfos.count, 2, "There are two users")
}
}
47 changes: 47 additions & 0 deletions KubeContextTests/TestData/config-with-null.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: snipped-cert
server: redacted-url
name: dev-cluster
- cluster:
certificate-authority-data: snipped-cert
server: redacted-url
name: prod-cluster
contexts:
- context:
cluster: dev-cluster
user: dev-user
name: dev
- context:
cluster: prod-cluster
user: prod-user
name: prod
current-context: dev
kind: Config
preferences: {}
users:
- name: dev-user
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args:
- token
- -i
- redacted-url
- -r
- redacted-arn
command: aws-iam-authenticator
env: null
- name: prod-user
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args:
- token
- -i
- redacted-url
- -r
- redacted-arn
command: aws-iam-authenticator
env: null
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target 'KubeContext' do
use_frameworks!

# Pods for KubeContext
pod 'Yams'
pod 'Yams', '~> 1.0.2'
pod 'SwiftyStoreKit'

end
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- SwiftyStoreKit (0.14.1)
- Yams (1.0.0)
- Yams (1.0.2)

DEPENDENCIES:
- SwiftyStoreKit
- Yams
- Yams (~> 1.0.2)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
Expand All @@ -13,8 +13,8 @@ SPEC REPOS:

SPEC CHECKSUMS:
SwiftyStoreKit: a5cdece4327f3943eb72fa81aebe3aa6684b5eab
Yams: a01cdee527b3a82a3e192255b34ad5aacdf96b8c
Yams: fcdf51397d30c85f8ac780e917bcf7bdf6bc654b

PODFILE CHECKSUM: 54099b2c26581357952df5ecabfc6e12d705cdb6
PODFILE CHECKSUM: d95677dbdb75cd2c1572aa5267cf323ccc58a4ea

COCOAPODS: 1.5.3
8 changes: 4 additions & 4 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/Target Support Files/Yams/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Pods/Yams/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 32 additions & 31 deletions Pods/Yams/Sources/CYaml/src/api.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e53108c

Please sign in to comment.